Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6464222

(str) String.CaseInsensitiveComparator small code improvement

XMLWordPrintable

    • b03
    • generic
    • generic
    • Not verified

      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);

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: