Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X ce17f0ebb -> d50b7ab6a
Minor refactoring (cherry picked from commit 98bb3a8) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d50b7ab6 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d50b7ab6 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d50b7ab6 Branch: refs/heads/GROOVY_2_5_X Commit: d50b7ab6a9abc3f0f7f68cfd3058b1d66139fa0e Parents: ce17f0e Author: sunlan <[email protected]> Authored: Wed Dec 6 16:32:36 2017 +0800 Committer: sunlan <[email protected]> Committed: Wed Dec 6 17:05:21 2017 +0800 ---------------------------------------------------------------------- src/main/groovy/lang/GString.java | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/d50b7ab6/src/main/groovy/lang/GString.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/lang/GString.java b/src/main/groovy/lang/GString.java index 7a520fe..8323bf2 100644 --- a/src/main/groovy/lang/GString.java +++ b/src/main/groovy/lang/GString.java @@ -57,6 +57,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable, } }; public static final String[] EMPTY_STRING_ARRAY = new String[0]; + public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; private final Object[] values; @@ -118,28 +119,7 @@ public abstract class GString extends GroovyObjectSupport implements Comparable, } public GString plus(String that) { - String[] currentStrings = getStrings(); - String[] newStrings; - Object[] newValues; - - boolean appendToLastString = currentStrings.length > getValues().length; - - if (appendToLastString) { - newStrings = new String[currentStrings.length]; - } else { - newStrings = new String[currentStrings.length + 1]; - } - newValues = new Object[getValues().length]; - int lastIndex = currentStrings.length; - System.arraycopy(currentStrings, 0, newStrings, 0, lastIndex); - System.arraycopy(getValues(), 0, newValues, 0, getValues().length); - if (appendToLastString) { - newStrings[lastIndex - 1] += that; - } else { - newStrings[lastIndex] = that; - } - - return new GStringImpl(newValues, newStrings); + return plus(new GStringImpl(EMPTY_OBJECT_ARRAY, new String[] { that })); } public int getValueCount() {
