From 02f3d42b03492c987c35ea5e324177d8a309d8d9 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Sat, 26 Apr 2008 16:46:44 +0000 Subject: 2008-04-26 Ian Rogers * java/util/ArrayList (raiseBoundsError): new method to raise bound exceptions in uncommon case. (checkBoundInclusive): use raiseBoundsError. (checkBoundExclusive): likewise. * java/util/ArrayList (raiseBoundsError): new method to raise bound exceptions in uncommon case. (checkBoundInclusive): use raiseBoundsError. (checkBoundExclusive): likewise. --- java/util/ArrayList.java | 21 +++++++++++++++++---- java/util/Vector.java | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'java') diff --git a/java/util/ArrayList.java b/java/util/ArrayList.java index 0693049b5..1fb25d801 100644 --- a/java/util/ArrayList.java +++ b/java/util/ArrayList.java @@ -472,8 +472,7 @@ public class ArrayList extends AbstractList // use of a negative index will cause an ArrayIndexOutOfBoundsException, // a subclass of the required exception, with no effort on our part. if (index > size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " - + size); + raiseBoundsError(index); } /** @@ -488,10 +487,24 @@ public class ArrayList extends AbstractList // use of a negative index will cause an ArrayIndexOutOfBoundsException, // a subclass of the required exception, with no effort on our part. if (index >= size) - throw new IndexOutOfBoundsException("Index: " + index + ", Size: " - + size); + raiseBoundsError(index); } + /** + * Raise the ArrayIndexOfOutBoundsException. + * + * @param index the index of the access + * @throws IndexOutOfBoundsException unconditionally + */ + private void raiseBoundsError(int index) + { + // Implementaion note: put in a separate method to make the JITs job easier + // (separate common from uncommon code at method boundaries when trivial to + // do so). + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size); + } + + /** * Remove from this list all elements contained in the given collection. * This is not public, due to Sun's API, but this performs in linear diff --git a/java/util/Vector.java b/java/util/Vector.java index 0c6a7615e..101a78dda 100644 --- a/java/util/Vector.java +++ b/java/util/Vector.java @@ -909,7 +909,7 @@ public class Vector extends AbstractList // use of a negative index will cause an ArrayIndexOutOfBoundsException // with no effort on our part. if (index > elementCount) - throw new ArrayIndexOutOfBoundsException(index + " > " + elementCount); + raiseBoundsError(index, " > "); } /** @@ -924,9 +924,24 @@ public class Vector extends AbstractList // use of a negative index will cause an ArrayIndexOutOfBoundsException // with no effort on our part. if (index >= elementCount) - throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount); + raiseBoundsError(index, " >= "); } + /** + * Raise the ArrayIndexOfOutBoundsException. + * + * @param index the index of the access + * @param operator the operator to include in the error message + * @throws IndexOutOfBoundsException unconditionally + */ + private void raiseBoundsError(int index, String operator) + { + // Implementaion note: put in a separate method to make the JITs job easier + // (separate common from uncommon code at method boundaries when trivial to + // do so). + throw new ArrayIndexOutOfBoundsException(index + operator + elementCount); + } + /** * Serializes this object to the given stream. * -- cgit v1.2.1