harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r983240 - in /harmony/enhanced/java/branches/java6: ./ classlib/ classlib/depends/libs/ classlib/modules/luni/src/main/java/java/util/ArrayList.java drlvm/ jdktools/
Date Sat, 07 Aug 2010 15:12:20 GMT
Author: hindessm
Date: Sat Aug  7 15:12:19 2010
New Revision: 983240

URL: http://svn.apache.org/viewvc?rev=983240&view=rev
Log:
Merge change from /harmony/enhanced/java/trunk@982250:

  r982250 | hindessm | 2010-08-04 14:49:32 +0100 (Wed, 04 Aug 2010) | 10 lines
  
  Move exception handling to beginning of methods.
  
  Make sure all exceptions are using Integer.valueOf(...) for int arguments.
  
  In case where the exception moves lead to restructuring of if else
  statements, I also re-ordered some of the statements to make the more
  complicated conditions/cases come later.  This should actually
  marginally help optimize for the (more typical?) cases of adding items
  to the beginning and/or end of the list.
  


Modified:
    harmony/enhanced/java/branches/java6/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/depends/libs/   (props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/ArrayList.java
    harmony/enhanced/java/branches/java6/drlvm/   (props changed)
    harmony/enhanced/java/branches/java6/jdktools/   (props changed)

Propchange: harmony/enhanced/java/branches/java6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug  7 15:12:19 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/java/branches/mrh:935751-941490
-/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183
+/harmony/enhanced/java/trunk:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250
 /harmony/enhanced/trunk:476395-929252
 /incubator/harmony/enhanced/trunk:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug  7 15:12:19 2010
@@ -1,7 +1,7 @@
 /harmony/enhanced/classlib/trunk:713674-735919,765923-926091,926318-926838
 /harmony/enhanced/classlib/trunk/working_classlib:884014-884286
 /harmony/enhanced/java/branches/mrh/classlib:935751-941490
-/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183
+/harmony/enhanced/java/trunk/classlib:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250
 /harmony/enhanced/trunk/classlib:476395-929252
 /harmony/enhanced/trunk/working_classlib:476396-920147
 /incubator/harmony/enhanced/trunk/classlib:292550-476394

Propchange: harmony/enhanced/java/branches/java6/classlib/depends/libs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug  7 15:12:19 2010
@@ -1,4 +1,4 @@
 /harmony/enhanced/classlib/trunk/depends/libs:544451-926091
-/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183
+/harmony/enhanced/java/trunk/classlib/depends/libs:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250
 /harmony/enhanced/trunk/classlib/depends/libs:476395-929252
 /incubator/harmony/enhanced/trunk/classlib/depends/libs:292550-476394

Modified: harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/ArrayList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/ArrayList.java?rev=983240&r1=983239&r2=983240&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/ArrayList.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/luni/src/main/java/java/util/ArrayList.java
Sat Aug  7 15:12:19 2010
@@ -105,7 +105,24 @@ public class ArrayList<E> extends Abstra
     @Override
     public void add(int location, E object) {
         int size = lastIndex - firstIndex;
-        if (0 < location && location < size) {
+        if (location < 0 || location > size) {
+            throw new IndexOutOfBoundsException(
+                    // luni.0A=Index: {0}, Size: {1}
+                    Messages.getString("luni.0A", //$NON-NLS-1$
+                            Integer.valueOf(location),
+                            Integer.valueOf(size)));
+        }
+        if (location == 0) {
+            if (firstIndex == 0) {
+                growAtFront(1);
+            }
+            array[--firstIndex] = object;
+        } else if (location == size) {
+            if (lastIndex == array.length) {
+                growAtEnd(1);
+            }
+            array[lastIndex++] = object;
+        } else { // must be case: (0 < location && location < size)
             if (firstIndex == 0 && lastIndex == array.length) {
                 growForInsert(location, 1);
             } else if ((location < size / 2 && firstIndex > 0)
@@ -119,22 +136,6 @@ public class ArrayList<E> extends Abstra
                 lastIndex++;
             }
             array[location + firstIndex] = object;
-        } else if (location == 0) {
-            if (firstIndex == 0) {
-                growAtFront(1);
-            }
-            array[--firstIndex] = object;
-        } else if (location == size) {
-            if (lastIndex == array.length) {
-                growAtEnd(1);
-            }
-            array[lastIndex++] = object;
-        } else {
-            throw new IndexOutOfBoundsException(
-                    // luni.0A=Index: {0}, Size: {1}
-                    Messages.getString("luni.0A", //$NON-NLS-1$
-                            Integer.valueOf(location),
-                            Integer.valueOf(lastIndex - firstIndex)));
         }
 
         modCount++;
@@ -179,7 +180,7 @@ public class ArrayList<E> extends Abstra
                     // luni.0A=Index: {0}, Size: {1}
                     Messages.getString("luni.0A", //$NON-NLS-1$
                             Integer.valueOf(location),
-                            Integer.valueOf(lastIndex - firstIndex)));
+                            Integer.valueOf(size)));
         }
         if (this == collection) {
             collection = (ArrayList)clone();
@@ -190,7 +191,15 @@ public class ArrayList<E> extends Abstra
             return false;
         }
 
-        if (0 < location && location < size) {
+        if (location == 0) {
+            growAtFront(growSize);
+            firstIndex -= growSize;
+        } else if (location == size) {
+            if (lastIndex > array.length - growSize) {
+                growAtEnd(growSize);
+            }
+            lastIndex += growSize;
+        } else { // must be case: (0 < location && location < size)
             if (array.length - size < growSize) {
                 growForInsert(location, growSize);
             } else if ((location < size / 2 && firstIndex > 0)
@@ -211,14 +220,6 @@ public class ArrayList<E> extends Abstra
                         - location);
                 lastIndex += growSize;
             }
-        } else if (location == 0) {
-            growAtFront(growSize);
-            firstIndex -= growSize;
-        } else if (location == size) {
-            if (lastIndex > array.length - growSize) {
-                growAtEnd(growSize);
-            }
-            lastIndex += growSize;
         }
 
         System.arraycopy(dumparray, 0, this.array, location + firstIndex,
@@ -329,14 +330,15 @@ public class ArrayList<E> extends Abstra
 
     @Override
     public E get(int location) {
-        if (0 <= location && location < (lastIndex - firstIndex)) {
-            return array[firstIndex + location];
-        }
-        throw new IndexOutOfBoundsException(
+        int size = lastIndex - firstIndex;
+        if (location < 0 || location >= size) {
+            throw new IndexOutOfBoundsException(
                 // luni.0A=Index: {0}, Size: {1}
                 Messages.getString("luni.0A", //$NON-NLS-1$
                         Integer.valueOf(location),
-                        Integer.valueOf(lastIndex - firstIndex)));
+                        Integer.valueOf(size)));
+        }
+        return array[firstIndex + location];
     }
 
     private void growAtEnd(int required) {
@@ -476,35 +478,34 @@ public class ArrayList<E> extends Abstra
     public E remove(int location) {
         E result;
         int size = lastIndex - firstIndex;
-        if (0 <= location && location < size) {
-            if (location == size - 1) {
-                result = array[--lastIndex];
-                array[lastIndex] = null;
-            } else if (location == 0) {
-                result = array[firstIndex];
-                array[firstIndex++] = null;
-            } else {
-                int elementIndex = firstIndex + location;
-                result = array[elementIndex];
-                if (location < size / 2) {
-                    System.arraycopy(array, firstIndex, array, firstIndex + 1,
-                            location);
-                    array[firstIndex++] = null;
-                } else {
-                    System.arraycopy(array, elementIndex + 1, array,
-                            elementIndex, size - location - 1);
-                    array[--lastIndex] = null;
-                }
-            }
-            if (firstIndex == lastIndex) {
-                firstIndex = lastIndex = 0;
-            }
-        } else {
+        if (location < 0 || location >= size) {
             throw new IndexOutOfBoundsException(
                     // luni.0A=Index: {0}, Size: {1}
                     Messages.getString("luni.0A", //$NON-NLS-1$
                             Integer.valueOf(location),
-                            Integer.valueOf(lastIndex - firstIndex)));
+                            Integer.valueOf(size)));
+        }
+        if (location == size - 1) {
+            result = array[--lastIndex];
+            array[lastIndex] = null;
+        } else if (location == 0) {
+            result = array[firstIndex];
+            array[firstIndex++] = null;
+        } else {
+            int elementIndex = firstIndex + location;
+            result = array[elementIndex];
+            if (location < size / 2) {
+                System.arraycopy(array, firstIndex, array, firstIndex + 1,
+                                 location);
+                array[firstIndex++] = null;
+            } else {
+                System.arraycopy(array, elementIndex + 1, array,
+                                 elementIndex, size - location - 1);
+                array[--lastIndex] = null;
+            }
+        }
+        if (firstIndex == lastIndex) {
+            firstIndex = lastIndex = 0;
         }
 
         modCount++;
@@ -534,31 +535,41 @@ public class ArrayList<E> extends Abstra
      */
     @Override
     protected void removeRange(int start, int end) {
-        if (start >= 0 && start <= end && end <= (lastIndex - firstIndex))
{
-            if (start == end) {
-                return;
-            }
-            int size = lastIndex - firstIndex;
-            if (end == size) {
-                Arrays.fill(array, firstIndex + start, lastIndex, null);
-                lastIndex = firstIndex + start;
-            } else if (start == 0) {
-                Arrays.fill(array, firstIndex, firstIndex + end, null);
-                firstIndex += end;
-            } else {
-                System.arraycopy(array, firstIndex + end, array, firstIndex
-                        + start, size - end);
-                int newLast = lastIndex + start - end;
-                Arrays.fill(array, newLast, lastIndex, null);
-                lastIndex = newLast;
-            }
-            modCount++;
-        } else {
+        int size = lastIndex - firstIndex;
+        if (start < 0) {
             throw new IndexOutOfBoundsException(
                     // luni.0B=Array index out of range: {0}
                     Messages.getString("luni.0B", //$NON-NLS-1$
-                            lastIndex - firstIndex - end));
+                                       Integer.valueOf(start)));
+        } else if (end > size) {
+            throw new IndexOutOfBoundsException(
+                    // luni.0A=Index: {0}, Size: {1}
+                    Messages.getString("luni.0A", //$NON-NLS-1$
+                               Integer.valueOf(end), Integer.valueOf(size)));
+        } else if (start > end) {
+            throw new IndexOutOfBoundsException(
+                    // luni.35=Start index ({0}) is greater than end index ({1})
+                    Messages.getString("luni.35", //$NON-NLS-1$
+                               Integer.valueOf(start), Integer.valueOf(end)));
+        }
+
+        if (start == end) {
+            return;
+        }
+        if (end == size) {
+            Arrays.fill(array, firstIndex + start, lastIndex, null);
+            lastIndex = firstIndex + start;
+        } else if (start == 0) {
+            Arrays.fill(array, firstIndex, firstIndex + end, null);
+            firstIndex += end;
+        } else {
+            System.arraycopy(array, firstIndex + end, array, firstIndex
+                             + start, size - end);
+            int newLast = lastIndex + start - end;
+            Arrays.fill(array, newLast, lastIndex, null);
+            lastIndex = newLast;
         }
+        modCount++;
     }
 
     /**
@@ -575,16 +586,17 @@ public class ArrayList<E> extends Abstra
      */
     @Override
     public E set(int location, E object) {
-        if (0 <= location && location < (lastIndex - firstIndex)) {
-            E result = array[firstIndex + location];
-            array[firstIndex + location] = object;
-            return result;
+        int size = lastIndex - firstIndex;
+        if (location < 0 || location >= size) {
+            throw new IndexOutOfBoundsException(
+                    // luni.0A=Index: {0}, Size: {1}
+                    Messages.getString("luni.0A", //$NON-NLS-1$
+                            Integer.valueOf(location),
+                            Integer.valueOf(size)));
         }
-        throw new IndexOutOfBoundsException(
-                // luni.0A=Index: {0}, Size: {1}
-                Messages.getString("luni.0A", //$NON-NLS-1$
-                        Integer.valueOf(location),
-                        Integer.valueOf(lastIndex - firstIndex)));
+        E result = array[firstIndex + location];
+        array[firstIndex + location] = object;
+        return result;
     }
 
     /**

Propchange: harmony/enhanced/java/branches/java6/drlvm/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug  7 15:12:19 2010
@@ -1,5 +1,5 @@
 /harmony/enhanced/java/branches/mrh/drlvm:935751-941490
-/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183
+/harmony/enhanced/java/trunk/drlvm:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250
 /harmony/enhanced/trunk/drlvm:476395-929252
 /harmony/enhanced/trunk/working_vm:476396-920147
 /incubator/harmony/enhanced/trunk/drlvm:292550-476394

Propchange: harmony/enhanced/java/branches/java6/jdktools/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Aug  7 15:12:19 2010
@@ -1,4 +1,4 @@
-/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183
+/harmony/enhanced/java/trunk/jdktools:929253-979569,979593,979613,979615,979647,979659,979682,979897,980326,980632,981356,981763,981811,981820,982146,982148,982183,982250
 /harmony/enhanced/jdktools/trunk:630107-925933
 /harmony/enhanced/trunk/jdktools:476395-929252
 /harmony/enhanced/trunk/working_jdktools:476396-920147



Mime
View raw message