JDK-6464222 : (str) String.CaseInsensitiveComparator small code improvement
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-08-25
  • Updated: 2011-05-17
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b03Fixed
Related Reports
Relates :  
Description
String.CaseInsensitiveComparator stupidly
initializes two indices to zero and increments both,
when only one index is needed.

--- /u/martin/ws/mustang/src/share/classes/java/lang/String.java	2006-06-12 09:57:08.229718000 -0700
+++ /u/martin/ws/process/src/share/classes/java/lang/String.java	2006-08-25 14:52:32.858262000 -0700
@@ -1215,10 +1215,12 @@
 	private static final long serialVersionUID = 8575799808933029326L;
 
         public int compare(String s1, String s2) {
-            int n1=s1.length(), n2=s2.length();
-            for (int i1=0, i2=0; i1<n1 && i2<n2; i1++, i2++) {
-                char c1 = s1.charAt(i1);
-                char c2 = s2.charAt(i2);
+	    int n1 = s1.length();
+	    int n2 = s2.length();
+	    int min = Math.min(n1, n2);
+	    for (int i = 0; i < min; i++) {
+		char c1 = s1.charAt(i);
+		char c2 = s2.charAt(i);
                 if (c1 != c2) {
                     c1 = Character.toUpperCase(c1);
                     c2 = Character.toUpperCase(c2);

Comments
EVALUATION A fine idea.
25-08-2006