summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorIan Rogers <ian.rogers@manchester.ac.uk>2008-04-26 16:46:44 +0000
committerIan Rogers <ian.rogers@manchester.ac.uk>2008-04-26 16:46:44 +0000
commit02f3d42b03492c987c35ea5e324177d8a309d8d9 (patch)
tree4d84fb22e562866882d3d5f4a8760a91b999ee5f /java
parent03a6b8faef9f3bf1247b064243af2f4d192f09a4 (diff)
downloadclasspath-02f3d42b03492c987c35ea5e324177d8a309d8d9.tar.gz
2008-04-26 Ian Rogers <ian.rogers@manchester.ac.uk>
* 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.
Diffstat (limited to 'java')
-rw-r--r--java/util/ArrayList.java21
-rw-r--r--java/util/Vector.java19
2 files changed, 34 insertions, 6 deletions
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<E> extends AbstractList<E>
// 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,11 +487,25 @@ public class ArrayList<E> extends AbstractList<E>
// 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
* time while the default behavior of AbstractList would be quadratic.
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<T> extends AbstractList<T>
// 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,10 +924,25 @@ public class Vector<T> extends AbstractList<T>
// 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.
*
* @param s the stream to write to