8056951: pico-optimize contains(Object) methods
Summary: use idiiom >= 0 consistently to check for valid index
Reviewed-by: mduigou
--- a/jdk/src/java.base/share/classes/java/lang/String.java Fri Sep 05 15:09:05 2014 +0200
+++ b/jdk/src/java.base/share/classes/java/lang/String.java Fri Aug 29 14:50:15 2014 -0700
@@ -2119,7 +2119,7 @@
* @since 1.5
*/
public boolean contains(CharSequence s) {
- return indexOf(s.toString()) > -1;
+ return indexOf(s.toString()) >= 0;
}
/**
--- a/jdk/src/java.base/share/classes/java/util/Arrays.java Fri Sep 05 15:09:05 2014 +0200
+++ b/jdk/src/java.base/share/classes/java/util/Arrays.java Fri Aug 29 14:50:15 2014 -0700
@@ -3865,7 +3865,7 @@
@Override
public boolean contains(Object o) {
- return indexOf(o) != -1;
+ return indexOf(o) >= 0;
}
@Override
--- a/jdk/src/java.base/share/classes/java/util/LinkedList.java Fri Sep 05 15:09:05 2014 +0200
+++ b/jdk/src/java.base/share/classes/java/util/LinkedList.java Fri Aug 29 14:50:15 2014 -0700
@@ -314,7 +314,7 @@
* @return {@code true} if this list contains the specified element
*/
public boolean contains(Object o) {
- return indexOf(o) != -1;
+ return indexOf(o) >= 0;
}
/**
--- a/jdk/src/java.base/share/classes/java/util/PriorityQueue.java Fri Sep 05 15:09:05 2014 +0200
+++ b/jdk/src/java.base/share/classes/java/util/PriorityQueue.java Fri Aug 29 14:50:15 2014 -0700
@@ -406,7 +406,7 @@
* @return {@code true} if this queue contains the specified element
*/
public boolean contains(Object o) {
- return indexOf(o) != -1;
+ return indexOf(o) >= 0;
}
/**