harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r643968 - in /harmony/enhanced/classlib/trunk/modules: archive/src/main/java/java/util/jar/Attributes.java nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Date Wed, 02 Apr 2008 16:48:50 GMT
Author: tellison
Date: Wed Apr  2 09:48:44 2008
New Revision: 643968

URL: http://svn.apache.org/viewvc?rev=643968&view=rev
Log:
Apply slightly modified patch for HARMONY-5679 ([classlib][archive] UTF-8 decoder & Attributes.Name.hashCode
optimizations)

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
    harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java?rev=643968&r1=643967&r2=643968&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
Wed Apr  2 09:48:44 2008
@@ -138,7 +138,8 @@
             if (hashCode == 0) {
                 int hash = 0, multiplier = 1;
                 for (int i = name.length - 1; i >= 0; i--) {
-                    hash += Util.toASCIIUpperCase(name[i]) * multiplier;
+                    // 'A' & 0xDF == 'a' & 0xDF, ..., 'Z' & 0xDF == 'z' &
0xDF
+                    hash += (name[i] & 0xDF) * multiplier;
                     int shifted = multiplier << 5;
                     multiplier = shifted - multiplier;
                 }

Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java?rev=643968&r1=643967&r2=643968&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Wed Apr  2 09:48:44 2008
@@ -26,8 +26,7 @@
 
 public class UTF_8 extends Charset {
 
-
-    // The next table contains information about UTF-8 charset and 
+    // The next table contains information about UTF-8 charset and
     // correspondence of 1st byte to the length of sequence
     // For information please visit http://www.ietf.org/rfc/rfc3629.txt
     //
@@ -41,66 +40,58 @@
     // 1111ouuu  1ouuzzzz  1oyyyyyy  1oxxxxxx   000uuuuu zzzzyyyy yyxxxxxx
 
     private static final int remainingBytes[] = {
-        // oxxxxxxx
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        // 1owwwwww
-        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-        // 11oyyyyy
-         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
-         1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
-        // 111ozzzz
-         2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
-        // 1111ouuu
-         3,  3,  3,  3,  3,  3,  3,  3,
-        // > 11110111
-        -1, -1, -1, -1, -1, -1, -1, -1
-    };
+            // 1owwwwww
+            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+            -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+            // 11oyyyyy
+            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+            1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+            // 111ozzzz
+            2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+            // 1111ouuu
+            3, 3, 3, 3, 3, 3, 3, 3,
+            // > 11110111
+            -1, -1, -1, -1, -1, -1, -1, -1 };
 
     private static final int remainingNumbers[] = {
-        0,       //  0                 1                 2                3
-        12416,   // (11o00000b <<  6)+(1o000000b)
-        925824,  // (111o0000b << 12)+(1o000000b <<  6)+(1o000000b)
-        63447168 // (1111o000b << 18)+(1o000000b << 12)+(1o000000b << 6)+(1o000000b)
+                   0, //                0                 1                2           3
+                4224, // (01o00000b <<  6)+(1o000000b)
+              401536, // (011o0000b << 12)+(1o000000b <<  6)+(1o000000b)
+            29892736  // (0111o000b << 18)+(1o000000b << 12)+(1o000000b <<
6)+(1o000000b)
     };
-    
+
     public UTF_8(String canonicalName, String[] aliases) {
         super(canonicalName, aliases);
     }
 
+    @Override
+    @SuppressWarnings("nls")
     public boolean contains(Charset cs) {
         return cs.name().equalsIgnoreCase("UTF-8")
-            || cs.name().equalsIgnoreCase("US-ASCII")
-            || cs.name().equalsIgnoreCase("KOI8-R")
-            || cs.name().equalsIgnoreCase("windows-1250")
-            || cs.name().equalsIgnoreCase("windows-1251")
-            || cs.name().equalsIgnoreCase("windows-1252")
-            || cs.name().equalsIgnoreCase("windows-1253")
-            || cs.name().equalsIgnoreCase("windows-1254")
-            || cs.name().equalsIgnoreCase("windows-1257")
-            || cs.name().equalsIgnoreCase("ISO-8859-1")
-            || cs.name().equalsIgnoreCase("ISO-8859-2")
-            || cs.name().equalsIgnoreCase("ISO-8859-4")
-            || cs.name().equalsIgnoreCase("ISO-8859-5")
-            || cs.name().equalsIgnoreCase("ISO-8859-7")
-            || cs.name().equalsIgnoreCase("ISO-8859-9")
-            || cs.name().equalsIgnoreCase("ISO-8859-10")
-            || cs.name().equalsIgnoreCase("ISO-8859-13")
-            || cs.name().equalsIgnoreCase("ISO-8859-14")
-            || cs.name().equalsIgnoreCase("ISO-8859-15")
-            || cs.name().equalsIgnoreCase("ISO-8859-16")
-            || cs.name().equalsIgnoreCase("UTF-16")
-            || cs.name().equalsIgnoreCase("UTF-16LE")
-            || cs.name().equalsIgnoreCase("UTF-16BE");
+                || cs.name().equalsIgnoreCase("US-ASCII")
+                || cs.name().equalsIgnoreCase("KOI8-R")
+                || cs.name().equalsIgnoreCase("windows-1250")
+                || cs.name().equalsIgnoreCase("windows-1251")
+                || cs.name().equalsIgnoreCase("windows-1252")
+                || cs.name().equalsIgnoreCase("windows-1253")
+                || cs.name().equalsIgnoreCase("windows-1254")
+                || cs.name().equalsIgnoreCase("windows-1257")
+                || cs.name().equalsIgnoreCase("ISO-8859-1")
+                || cs.name().equalsIgnoreCase("ISO-8859-2")
+                || cs.name().equalsIgnoreCase("ISO-8859-4")
+                || cs.name().equalsIgnoreCase("ISO-8859-5")
+                || cs.name().equalsIgnoreCase("ISO-8859-7")
+                || cs.name().equalsIgnoreCase("ISO-8859-9")
+                || cs.name().equalsIgnoreCase("ISO-8859-10")
+                || cs.name().equalsIgnoreCase("ISO-8859-13")
+                || cs.name().equalsIgnoreCase("ISO-8859-14")
+                || cs.name().equalsIgnoreCase("ISO-8859-15")
+                || cs.name().equalsIgnoreCase("ISO-8859-16")
+                || cs.name().equalsIgnoreCase("UTF-16")
+                || cs.name().equalsIgnoreCase("UTF-16LE")
+                || cs.name().equalsIgnoreCase("UTF-16BE");
     }
 
     public CharsetDecoder newDecoder() {
@@ -118,60 +109,54 @@
         }
 
         protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
-            int outRemaining = out.remaining(); 
+            int outRemaining = out.remaining();
             int pos = in.position();
             int limit = in.limit();
-            if(in.hasArray() && out.hasArray()) {
-                byte[] bArr;
-                char[] cArr;
-            	bArr = in.array();
-            	cArr = out.array();
-                int outPos = out.position();
-                int x = pos;
-                try {
-                	for(x=pos; x<pos+in.remaining(); x++) {
-                        if (outRemaining == 0) {
-                        	in.position(x-1); out.position(outPos);
-                            return CoderResult.OVERFLOW;
-                        }
-
-                        int jchar = (bArr[x] & 0xFF);
+            if (in.hasArray() && out.hasArray()) {
+                final byte[] bArr = in.array();
+                final char[] cArr = out.array();
+                final int inIndexLimit = limit + in.arrayOffset();
+
+                int inIndex = pos + in.arrayOffset();
+                int outIndex = out.position() + out.arrayOffset();
+
+                // if someone would change the limit in process,
+                // he would face consequences
+                for (; inIndex < inIndexLimit && outRemaining > 0; inIndex++)
{
+                    int jchar = bArr[inIndex];
+                    if (jchar < 0) {
+                        jchar = jchar & 0x7F;
                         int tail = remainingBytes[jchar];
+
                         if (tail == -1) {
-                        	in.position(x); out.position(outPos);
+                            in.position(inIndex - in.arrayOffset());
+                            out.position(outIndex - out.arrayOffset());
                             return CoderResult.unmappableForLength(1);
                         }
-                        if (limit - x < 1 + tail) {
-                        	in.position(x); out.position(outPos);
-                            return CoderResult.UNDERFLOW;
+                        if (inIndexLimit - inIndex < 1 + tail) {
+                            break;
                         }
 
-                        if (tail > 0) {
-                            int nextByte;
-                            for (int i = 0; i < tail; i++) {
-                                nextByte = bArr[x+i+1] & 0xFF;
-                                if ((nextByte & 0xC0) != 0x80) {
-                                	in.position(x+i); out.position(outPos);
-                                    return CoderResult.malformedForLength(1 + i);
-                                }
-                                jchar = (jchar << 6) + nextByte;
+                        for (int i = 0; i < tail; i++) {
+                            int nextByte = bArr[inIndex + i + 1] & 0xFF;
+                            if ((nextByte & 0xC0) != 0x80) {
+                                in.position(inIndex - in.arrayOffset());
+                                out.position(outIndex - out.arrayOffset());
+                                return CoderResult.malformedForLength(1 + i);
                             }
-                            jchar -= remainingNumbers[tail];
-                            x += tail;
+                            jchar = (jchar << 6) + nextByte;
                         }
-
-                        cArr[outPos++] = (char) jchar;
-                        outRemaining--;
-                	}
-                	in.position(x); out.position(outPos);
-                	if(outRemaining == 0 && in.hasRemaining()) {
-                		return CoderResult.OVERFLOW;
-                	}
-                    return CoderResult.UNDERFLOW;
-                } finally {
-                    in.position(x);
+                        jchar -= remainingNumbers[tail];
+                        inIndex += tail;
+                    }
+                    pos++;
+                    cArr[outIndex++] = (char) jchar;
+                    outRemaining--;
                 }
-            	
+                in.position(inIndex - in.arrayOffset());
+                out.position(outIndex - out.arrayOffset());
+                return (outRemaining == 0 && inIndex < inIndexLimit) ? CoderResult.OVERFLOW
+                        : CoderResult.UNDERFLOW;
             } else {
                 try {
                     while (pos < limit) {
@@ -179,28 +164,30 @@
                             return CoderResult.OVERFLOW;
                         }
 
-                        int jchar = (in.get() & 0xFF);
-                        int tail = remainingBytes[jchar];
-                        if (tail == -1) {
-                            return CoderResult.unmappableForLength(1);
-                        }
-                        if (limit - pos < 1 + tail) {
-                            return CoderResult.UNDERFLOW;
-                        }
+                        int jchar = in.get();
+                        if (jchar < 0) {
+                            jchar = jchar & 0x7F;
+                            int tail = remainingBytes[jchar];
+                            if (tail == -1) {
+                                return CoderResult.unmappableForLength(1);
+                            }
+                            if (limit - pos < 1 + tail) {
+                                return CoderResult.UNDERFLOW;
+                            }
 
-                        if (tail > 0) {
                             int nextByte;
                             for (int i = 0; i < tail; i++) {
                                 nextByte = in.get() & 0xFF;
                                 if ((nextByte & 0xC0) != 0x80) {
-                                    return CoderResult.malformedForLength(1 + i);
+                                    return CoderResult
+                                            .malformedForLength(1 + i);
                                 }
                                 jchar = (jchar << 6) + nextByte;
                             }
                             jchar -= remainingNumbers[tail];
                             pos += tail;
+                            pos++;
                         }
-                        pos++;
 
                         out.put((char) jchar);
                         outRemaining--;
@@ -223,20 +210,21 @@
             int outRemaining = out.remaining();
             int pos = in.position();
             int limit = in.limit();
-            if(in.hasArray() && out.hasArray()) {
+            if (in.hasArray() && out.hasArray()) {
                 byte[] bArr;
                 char[] cArr;
                 int x = pos;
-            	bArr = out.array();
-            	cArr = in.array();
+                bArr = out.array();
+                cArr = in.array();
                 int outPos = out.position();
                 int rem = in.remaining();
-            	for(x=pos; x<pos+rem; x++) {
+                for (x = pos; x < pos + rem; x++) {
                     int jchar = (cArr[x] & 0xFFFF);
-                    
+
                     if (jchar <= 0x7F) {
                         if (outRemaining < 1) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.OVERFLOW;
                         }
                         bArr[outPos++] = (byte) (jchar & 0xFF);
@@ -244,7 +232,8 @@
                     } else if (jchar <= 0x7FF) {
 
                         if (outRemaining < 2) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.OVERFLOW;
                         }
                         bArr[outPos++] = (byte) (0xC0 + ((jchar >> 6) & 0x1F));
@@ -255,36 +244,40 @@
 
                         // in has to have one byte more.
                         if (limit <= x + 1) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.UNDERFLOW;
                         }
 
                         if (outRemaining < 4) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.OVERFLOW;
                         }
 
                         // The surrogate pair starts with a low-surrogate.
                         if (jchar >= 0xDC00) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.malformedForLength(1);
                         }
 
-                        int jchar2 = cArr[x+1] & 0xFFFF;
-                        
+                        int jchar2 = cArr[x + 1] & 0xFFFF;
+
                         // The surrogate pair ends with a high-surrogate.
                         if (jchar2 < 0xDC00) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.malformedForLength(1);
                         }
 
-                        // Note, the Unicode scalar value n is defined 
+                        // Note, the Unicode scalar value n is defined
                         // as follows:
-                        //   n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
+                        // n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
                         // Where jchar is a high-surrogate,
-                        //       jchar2 is a low-surrogate.
+                        // jchar2 is a low-surrogate.
                         int n = (jchar << 10) + jchar2 + 0xFCA02400;
-                        
+
                         bArr[outPos++] = (byte) (0xF0 + ((n >> 18) & 0x07));
                         bArr[outPos++] = (byte) (0x80 + ((n >> 12) & 0x3F));
                         bArr[outPos++] = (byte) (0x80 + ((n >> 6) & 0x3F));
@@ -295,7 +288,8 @@
                     } else {
 
                         if (outRemaining < 3) {
-                        	in.position(x); out.position(outPos);
+                            in.position(x);
+                            out.position(outPos);
                             return CoderResult.OVERFLOW;
                         }
                         bArr[outPos++] = (byte) (0xE0 + ((jchar >> 12) & 0x0F));
@@ -304,17 +298,18 @@
                         outRemaining -= 3;
                     }
                     if (outRemaining == 0) {
-                    	in.position(x+1); out.position(outPos);
+                        in.position(x + 1);
+                        out.position(outPos);
                         return CoderResult.OVERFLOW;
                     }
 
-            	    
-            	}
-            	if(rem!=0) {
-                	in.position(x); out.position(outPos);
-            	}
+                }
+                if (rem != 0) {
+                    in.position(x);
+                    out.position(outPos);
+                }
             } else {
-            	try {
+                try {
                     while (pos < limit) {
                         if (outRemaining == 0) {
                             return CoderResult.OVERFLOW;
@@ -356,17 +351,17 @@
                             }
 
                             int jchar2 = (in.get() & 0xFFFF);
-                            
+
                             // The surrogate pair ends with a high-surrogate.
                             if (jchar2 < 0xDC00) {
                                 return CoderResult.malformedForLength(1);
                             }
 
-                            // Note, the Unicode scalar value n is defined 
+                            // Note, the Unicode scalar value n is defined
                             // as follows:
-                            //   n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
+                            // n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
                             // Where jchar is a high-surrogate,
-                            //       jchar2 is a low-surrogate.
+                            // jchar2 is a low-surrogate.
                             int n = (jchar << 10) + jchar2 + 0xFCA02400;
 
                             out.put((byte) (0xF0 + ((n >> 18) & 0x07)));
@@ -392,8 +387,8 @@
                     in.position(pos);
                 }
             }
-            
-                return CoderResult.UNDERFLOW;
+
+            return CoderResult.UNDERFLOW;
         }
 
     }



Mime
View raw message