[jdom-interest] Attribute.getQualifiedName optimization [eg?]
Joseph Bowbeer
jozart at csi.com
Fri Apr 13 14:03:19 PDT 2001
Here's an slight but perhaps significant optimization for
Attribute.getQualifiedName.
It saves constructing a new StringBuffer and a new String when there's no
namespace prefix associated with the attribute. (This is fairly common,
right?)
Current:
public String getQualifiedName() {
StringBuffer qname = new StringBuffer();
// Add prefix, if needed
String prefix = namespace.getPrefix();
if ((prefix != null) && (!prefix.equals(""))) {
qname.append(prefix)
.append(":");
}
qname.append(name);
return qname.toString();
}
Proposed:
public String getQualifiedName() {
// Add prefix, if needed
String prefix = namespace.getPrefix();
if ((prefix != null) && (!prefix.equals(""))) {
return new StringBuffer(prefix)
.append(':')
.append(getName())
.toString();
} else {
return getName();
}
Additional Notes:
1. append(':') is more efficient than append(":") without any loss in
clarity.
2. What's the policy for calling accessors as opposed to accessing the
fields directly? In the proposed code, I have getQualifiedName invoke
getName in order to be more subclass-friendly.
--
Joe Bowbeer
More information about the jdom-interest
mailing list