harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r517531 - in /harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/jar/ main/java/org/apache/harmony/archive/util/ test/java/org/apache/harmony/archive/util/
Date Tue, 13 Mar 2007 05:13:43 GMT
Author: liangyx
Date: Mon Mar 12 22:13:42 2007
New Revision: 517531

URL: http://svn.apache.org/viewvc?view=rev&rev=517531
Log:
Apply patch for HARMONY-3355([classlib][archive]optimize case-mapping operation)

Added:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
  (with props)
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/
    harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/Attributes.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.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?view=diff&rev=517531&r1=517530&r2=517531
==============================================================================
--- 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
Mon Mar 12 22:13:42 2007
@@ -22,6 +22,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.harmony.archive.util.Util;
+
 /**
  * The Attributes class is used to store values for Manifest entries. Attributes
  * keys are generally instances of Attributes.Name. Values associated with
@@ -113,7 +115,7 @@
         @Override
         public int hashCode() {
             if (hashCode == 0) {
-                hashCode = name.toLowerCase().hashCode();
+                hashCode = Util.toASCIILowerCase("name").hashCode();
             }
             return hashCode;
         }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?view=diff&rev=517531&r1=517530&r2=517531
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Mon Mar 12 22:13:42 2007
@@ -82,7 +82,7 @@
             it = list.iterator();
             String line = it.next();
             if (line.length() < 7
-                    || !line.substring(0, 5).toLowerCase().equals("name:")) { //$NON-NLS-1$
+                    || !Util.toASCIILowerCase(line.substring(0, 5)).equals("name:")) { //$NON-NLS-1$
                 throw new IOException(Messages.getString("archive.23")); //$NON-NLS-1$
             }
             // Name: length required space char

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java?view=diff&rev=517531&r1=517530&r2=517531
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
Mon Mar 12 22:13:42 2007
@@ -27,6 +27,8 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import org.apache.harmony.archive.util.Util;
+
 /**
  * JarFile is used to read jar entries and their associated data from jar files.
  * 
@@ -288,27 +290,23 @@
         int dirLength = META_DIR.length();
 
         boolean signed = false;
+
         if (null != metaEntries) {
             for (ZipEntry entry : metaEntries) {
                 String entryName = entry.getName();
                 if (manifestEntry == null
                         && manifest == null
-                        && entryName.regionMatches(true, dirLength,
-                                MANIFEST_NAME, dirLength, MANIFEST_NAME
-                                        .length()
-                                        - dirLength)) {
+                        && Util.ASCIIIgnoreCaseRegionMatches(entryName,
+                                dirLength, MANIFEST_NAME, dirLength,
+                                MANIFEST_NAME.length() - dirLength)) {
                     manifestEntry = entry;
                     if (verifier == null) {
                         break;
                     }
-                } else if (verifier != null
-                        && entryName.length() > dirLength
-                        && (entryName.regionMatches(true,
-                                entryName.length() - 3, ".SF", 0, 3) //$NON-NLS-1$
-                                || entryName.regionMatches(true, entryName
-                                        .length() - 4, ".DSA", 0, 4) || entryName //$NON-NLS-1$
-                                .regionMatches(true, entryName.length() - 4,
-                                        ".RSA", 0, 4))) { //$NON-NLS-1$
+                } else if (verifier != null && entryName.length() > dirLength
+                        && (Util.ASCIIIgnoreCaseRegionMatches(entryName, entryName.length()
- 3, ".SF", 0 ,3) //$NON-NLS-1$
+                           || Util.ASCIIIgnoreCaseRegionMatches(entryName, entryName.length()
- 4, ".DSA", 0 ,4) //$NON-NLS-1$
+                           || Util.ASCIIIgnoreCaseRegionMatches(entryName, entryName.length()
- 4, ".RSA", 0 ,4))){ //$NON-NLS-1$
                     signed = true;
                     InputStream is = super.getInputStream(entry);
                     byte[] buf = new byte[is.available()];

Added: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java?view=auto&rev=517531
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
Mon Mar 12 22:13:42 2007
@@ -0,0 +1,68 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.archive.util;
+
+public class Util {
+
+    public static boolean ASCIIIgnoreCaseRegionMatches(String s1, int start1,
+            String s2, int start2, int length) {
+
+        if (s1 != null && s2 != null) {
+            if (start1 < 0 || length > s1.length() - start1) {
+                return false;
+            }
+            if (start2 < 0 || length > s2.length() - start2) {
+                return false;
+            }
+
+            s1 = s1.substring(start1, start1 + length);
+            s2 = s2.substring(start2, start2 + length);
+
+            return toASCIILowerCase(s1).equals(toASCIILowerCase(s2));
+        }
+        throw new NullPointerException();
+    }
+
+    public static String toASCIILowerCase(String s) {
+        int len = s.length();
+        StringBuilder buffer = new StringBuilder(len);
+        for (int i = 0; i < len; i++) {
+            char c = s.charAt(i);
+            if ('A' <= c && c <= 'Z') {
+                buffer.append((char) (c + ('a' - 'A')));
+            } else {
+                buffer.append(c);
+            }
+        }
+        return buffer.toString();
+    }
+
+    public static String toASCIIUpperCase(String s) {
+        int len = s.length();
+        StringBuilder buffer = new StringBuilder(len);
+        for (int i = 0; i < len; i++) {
+            char c = s.charAt(i);
+            if ('a' <= c && c <= 'z') {
+                buffer.append((char) (c - ('a' - 'A')));
+            } else {
+                buffer.append(c);
+            }
+        }
+        return buffer.toString();
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java?view=auto&rev=517531
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
Mon Mar 12 22:13:42 2007
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.archive.util;
+
+import junit.framework.TestCase;
+
+public class UtilTest extends TestCase {
+
+    public void testASCIIIgnoreCaseRegionMatches() {
+        String s1 = "abcdefghijklmnopqrstuvwxyz"; //$NON-NLS-1$
+        String s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //$NON-NLS-1$
+        for (int i = 0; i < s1.length(); i++) {
+            assertTrue(Util.ASCIIIgnoreCaseRegionMatches(s1, i, s2, i, s1
+                    .length()
+                    - i));
+        }
+    }
+
+    public void testToASCIILowerCase() {
+        assertEquals("abcdefghijklmnopqrstuvwxyz", Util //$NON-NLS-1$
+                .toASCIILowerCase("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); //$NON-NLS-1$
+
+        for (int i = 0; i < 255; i++) {
+            if (i >= 'a' && i <= 'z') {
+                continue;
+            }
+            if (i >= 'A' && i <= 'Z') {
+                continue;
+            }
+            String cString = "" + (char) i; //$NON-NLS-1$
+            assertEquals(cString, Util.toASCIILowerCase(cString));
+        }
+    }
+
+    public void testToASCIIUpperCase() {
+        assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Util //$NON-NLS-1$
+                .toASCIIUpperCase("abcdefghijklmnopqrstuvwxyz")); //$NON-NLS-1$
+
+        for (int i = 0; i < 255; i++) {
+            if (i >= 'a' && i <= 'z') {
+                continue;
+            }
+            if (i >= 'A' && i <= 'Z') {
+                continue;
+            }
+            String cString = "" + (char) i; //$NON-NLS-1$
+            assertEquals(cString, Util.toASCIIUpperCase(cString));
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/archive/util/UtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message