summaryrefslogtreecommitdiff
path: root/gnu/java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-03-17 03:04:16 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-03-17 03:04:16 +0000
commit4a47af06c3c29f0b1ccc304d3ace37aa5cdbeeb3 (patch)
treed211ca3820548030af5a9c1600d773cf51a14a35 /gnu/java
parentf8f874a297ff06b4acecbbd87286b1eb4b08d064 (diff)
downloadclasspath-4a47af06c3c29f0b1ccc304d3ace37aa5cdbeeb3.tar.gz
2008-03-17 Andrew John Hughes <gnu_andrew@member.fsf.org>
PR classpath/21869 * gnu/java/lang/CPStringBuilder.java: (indexOf(String,int)): Use regionMatches from String. (lastIndexOf(String,int)): Likewise. (regionMatches(int,String)): Removed broken code. (substring(int,int)): Rearrange index computation so it is only computed if valid.
Diffstat (limited to 'gnu/java')
-rw-r--r--gnu/java/lang/CPStringBuilder.java32
1 files changed, 9 insertions, 23 deletions
diff --git a/gnu/java/lang/CPStringBuilder.java b/gnu/java/lang/CPStringBuilder.java
index 64da224e2..978a2043f 100644
--- a/gnu/java/lang/CPStringBuilder.java
+++ b/gnu/java/lang/CPStringBuilder.java
@@ -829,9 +829,11 @@ public final class CPStringBuilder
{
if (fromIndex < 0)
fromIndex = 0;
- int limit = count - str.length();
- for ( ; fromIndex <= limit; fromIndex++)
- if (regionMatches(fromIndex, str))
+ int olength = str.length();
+ int limit = count - olength;
+ String s = VMCPStringBuilder.toString(value, 0, count);
+ for (; fromIndex <= limit; ++fromIndex)
+ if (s.regionMatches(fromIndex, str, 0, olength))
return fromIndex;
return -1;
}
@@ -865,8 +867,10 @@ public final class CPStringBuilder
public int lastIndexOf(String str, int fromIndex)
{
fromIndex = Math.min(fromIndex, count - str.length());
+ String s = VMCPStringBuilder.toString(value, 0, count);
+ int olength = str.length();
for ( ; fromIndex >= 0; fromIndex--)
- if (regionMatches(fromIndex, str))
+ if (s.regionMatches(fromIndex, str, 0, olength))
return fromIndex;
return -1;
}
@@ -1013,24 +1017,6 @@ public final class CPStringBuilder
}
/**
- * Predicate which determines if a substring of this matches another String
- * starting at a specified offset for each String and continuing for a
- * specified length. This is more efficient than creating a String to call
- * indexOf on.
- *
- * @param toffset index to start comparison at for this String
- * @param other non-null String to compare to region of this
- * @return true if regions match, false otherwise
- * @see #indexOf(String, int)
- * @see #lastIndexOf(String, int)
- * @see String#regionMatches(boolean, int, String, int, int)
- */
- private boolean regionMatches(int toffset, String other)
- {
- return new String().regionMatches(toffset, other, 0, other.length());
- }
-
- /**
* Get the length of the <code>String</code> this <code>StringBuilder</code>
* would create. Not to be confused with the <em>capacity</em> of the
* <code>StringBuilder</code>.
@@ -1074,9 +1060,9 @@ public final class CPStringBuilder
*/
public String substring(int beginIndex, int endIndex)
{
- int len = endIndex - beginIndex;
if (beginIndex < 0 || endIndex > count || endIndex < beginIndex)
throw new StringIndexOutOfBoundsException();
+ int len = endIndex - beginIndex;
if (len == 0)
return "";
return VMCPStringBuilder.toString(value, beginIndex, len);