From 06da2f53713a45e25a7dc166b208cb42e691a60f Mon Sep 17 00:00:00 2001 From: lpriima Date: Mon, 26 Jan 2015 14:37:30 +0000 Subject: [PATCH] 8067471: Use private static final char[0] for empty Strings Reviewed-by: igerasim, redestad, shade --- src/share/classes/java/lang/String.java | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/share/classes/java/lang/String.java b/src/share/classes/java/lang/String.java index 483d1c68d..16edf705e 100644 --- a/src/share/classes/java/lang/String.java +++ b/src/share/classes/java/lang/String.java @@ -135,7 +135,7 @@ public final class String * unnecessary since Strings are immutable. */ public String() { - this.value = new char[0]; + this.value = "".value; } /** @@ -191,8 +191,14 @@ public final class String if (offset < 0) { throw new StringIndexOutOfBoundsException(offset); } - if (count < 0) { - throw new StringIndexOutOfBoundsException(count); + if (count <= 0) { + if (count < 0) { + throw new StringIndexOutOfBoundsException(count); + } + if (offset <= value.length) { + this.value = "".value; + return; + } } // Note: offset or count might be near -1>>>1. if (offset > value.length - count) { @@ -233,8 +239,14 @@ public final class String if (offset < 0) { throw new StringIndexOutOfBoundsException(offset); } - if (count < 0) { - throw new StringIndexOutOfBoundsException(count); + if (count <= 0) { + if (count < 0) { + throw new StringIndexOutOfBoundsException(count); + } + if (offset <= codePoints.length) { + this.value = "".value; + return; + } } // Note: offset or count might be near -1>>>1. if (offset > codePoints.length - count) { @@ -782,7 +794,7 @@ public final class String * subarray of {@code dst} starting at index {@code dstBegin} * and ending at index: *
-     *     dstbegin + (srcEnd-srcBegin) - 1
+     *     dstBegin + (srcEnd-srcBegin) - 1
      * 
* * @param srcBegin index of the first character in the string @@ -827,7 +839,7 @@ public final class String * dst} starting at index {@code dstBegin} and ending at index: * *
-     *     dstbegin + (srcEnd-srcBegin) - 1
+     *     dstBegin + (srcEnd-srcBegin) - 1
      * 
* * @deprecated This method does not properly convert characters into -- GitLab