summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <ian.rogers@manchester.ac.uk>2008-02-07 17:09:02 +0000
committerIan Rogers <ian.rogers@manchester.ac.uk>2008-02-07 17:09:02 +0000
commitf86cc4334538a58f41140225bdb822c69ab0b7e9 (patch)
tree6a013742f3ae0575db33718c3a5f8258977d6787
parenta5d85cdf1c0005cc4d8351e0f6cd7f7db87c6353 (diff)
downloadclasspath-f86cc4334538a58f41140225bdb822c69ab0b7e9.tar.gz
2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk>
* java/lang/String.java (replace): Only copy "live" portion of String. Use array copies in preference to clone. (toLowerCaseTurkish): likewise (toLowerCase): likewise (toUpperCaseTurkish): likewise (toUpperCase): likewise (toCharArray): Use array copies in preference to clone.
-rw-r--r--ChangeLog11
-rw-r--r--java/lang/String.java47
2 files changed, 37 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index d33f93154..5b9bd1340 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-02-07 Ian Rogers <ian.rogers@manchester.ac.uk>
+
+ * java/lang/String.java
+ (replace): Only copy "live" portion of String. Use array copies in preference
+ to clone.
+ (toLowerCaseTurkish): likewise
+ (toLowerCase): likewise
+ (toUpperCaseTurkish): likewise
+ (toUpperCase): likewise
+ (toCharArray): Use array copies in preference to clone.
+
2008-02-05 Ian Rogers <ian.rogers@manchester.ac.uk>
* gnu/java/lang/reflect/TypeSignature.java
diff --git a/java/lang/String.java b/java/lang/String.java
index 337b42803..6b57a2c39 100644
--- a/java/lang/String.java
+++ b/java/lang/String.java
@@ -1303,13 +1303,13 @@ public final class String
break;
if (i < 0)
return this;
- char[] newStr = (char[]) value.clone();
- newStr[x] = newChar;
+ char[] newStr = toCharArray();
+ newStr[x - offset] = newChar;
while (--i >= 0)
if (value[++x] == oldChar)
- newStr[x] = newChar;
+ newStr[x - offset] = newChar;
// Package constructor avoids an array copy.
- return new String(newStr, offset, count, true);
+ return new String(newStr, 0, count, true);
}
/**
@@ -1450,23 +1450,25 @@ public final class String
// Now we perform the conversion. Fortunately, there are no multi-character
// lowercase expansions in Unicode 3.0.0.
- char[] newStr = (char[]) value.clone();
+ char[] newStr = new char[count];
+ VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
do
{
char ch = value[x];
// Hardcoded special case.
if (ch != '\u0049')
{
- newStr[x++] = Character.toLowerCase(ch);
+ newStr[x - offset] = Character.toLowerCase(ch);
}
else
{
- newStr[x++] = '\u0131';
+ newStr[x - offset] = '\u0131';
}
+ x++;
}
while (--i >= 0);
// Package constructor avoids an array copy.
- return new String(newStr, offset, count, true);
+ return new String(newStr, 0, count, true);
}
/**
@@ -1504,16 +1506,18 @@ public final class String
// Now we perform the conversion. Fortunately, there are no
// multi-character lowercase expansions in Unicode 3.0.0.
- char[] newStr = (char[]) value.clone();
+ char[] newStr = new char[count];
+ VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
do
{
char ch = value[x];
// Hardcoded special case.
- newStr[x++] = Character.toLowerCase(ch);
+ newStr[x - offset] = Character.toLowerCase(ch);
+ x++;
}
while (--i >= 0);
// Package constructor avoids an array copy.
- return new String(newStr, offset, count, true);
+ return new String(newStr, 0, count, true);
}
}
@@ -1557,22 +1561,24 @@ public final class String
i = count;
if (expand == 0)
{
- char[] newStr = (char[]) value.clone();
+ char[] newStr = new char[count];
+ VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
while (--i >= 0)
{
char ch = value[x];
// Hardcoded special case.
if (ch != '\u0069')
{
- newStr[x++] = Character.toUpperCase(ch);
+ newStr[x - offset] = Character.toUpperCase(ch);
}
else
{
- newStr[x++] = '\u0130';
+ newStr[x - offset] = '\u0130';
}
+ x++;
}
// Package constructor avoids an array copy.
- return new String(newStr, offset, count, true);
+ return new String(newStr, 0, count, true);
}
// Expansion is necessary.
@@ -1642,14 +1648,16 @@ public final class String
i = count;
if (expand == 0)
{
- char[] newStr = (char[]) value.clone();
+ char[] newStr = new char[count];
+ VMSystem.arraycopy(value, offset, newStr, 0, count - (x - offset));
while (--i >= 0)
{
char ch = value[x];
- newStr[x++] = Character.toUpperCase(ch);
+ newStr[x - offset] = Character.toUpperCase(ch);
+ x++;
}
// Package constructor avoids an array copy.
- return new String(newStr, offset, count, true);
+ return new String(newStr, 0, count, true);
}
// Expansion is necessary.
@@ -1730,9 +1738,6 @@ public final class String
*/
public char[] toCharArray()
{
- if (count == value.length)
- return (char[]) value.clone();
-
char[] copy = new char[count];
VMSystem.arraycopy(value, offset, copy, 0, count);
return copy;