minchau 2005/04/06 22:41:48
Modified: java/src/org/apache/xml/serializer Encodings.java
Log:
Committing patch for XALANJ-2077. This performance modification is
estimated to shave 3% of the serialization stage of small documents.
Every little bit counts.
Revision Changes Path
1.12 +37 -3
xml-xalan/java/src/org/apache/xml/serializer/Encodings.java
Index: Encodings.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/Encodings.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Encodings.java 14 Oct 2004 21:45:05 -0000 1.11
+++ Encodings.java 7 Apr 2005 05:41:48 -0000 1.12
@@ -184,7 +184,7 @@
{
EncodingInfo ei;
- String normalizedEncoding = encoding.toUpperCase();
+ String normalizedEncoding = toUpperCaseFast(encoding);
ei = (EncodingInfo) _encodingTableKeyJava.get(normalizedEncoding);
if (ei == null)
ei = (EncodingInfo)
_encodingTableKeyMime.get(normalizedEncoding);
@@ -192,6 +192,40 @@
return ei.lastPrintable;
return m_defaultLastPrintable;
}
+
+ /**
+ * A fast and cheap way to uppercase a String that is
+ * only made of printable ASCII characters.
+ * @param s a String of ASCII characters
+ * @return an uppercased version of the input String,
+ * possibly the same String.
+ */
+ static private String toUpperCaseFast(final String s) {
+
+ boolean different = false;
+ final int mx = s.length();
+ char[] chars = new char[mx];
+ for (int i=0; i < mx; i++) {
+ char ch = s.charAt(i);
+ // is the character a lower case ASCII one?
+ if ('a' <= ch && ch <= 'z') {
+ // a cheap and fast way to uppercase that is good enough
+ ch = (char) (ch + ('A' - 'a'));
+ different = true; // the uppercased String is different
+ }
+ chars[i] = ch;
+ }
+
+ // A little optimization, don't call String.valueOf() if
+ // the uppercased string is the same as the input string.
+ final String upper;
+ if (different)
+ upper = String.valueOf(chars);
+ else
+ upper = s;
+
+ return upper;
+ }
/**
* Returns the last printable character for an unspecified
@@ -285,7 +319,7 @@
private static String convertJava2MimeEncoding(String encoding)
{
EncodingInfo enc =
- (EncodingInfo) _encodingTableKeyJava.get(encoding.toUpperCase());
+ (EncodingInfo)
_encodingTableKeyJava.get(toUpperCaseFast(encoding));
if (null != enc)
return enc.name;
return encoding;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]