Repository: groovy Updated Branches: refs/heads/master ae7b94731 -> 98bb3a8ab
Minor refactoring Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/98bb3a8a Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/98bb3a8a Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/98bb3a8a Branch: refs/heads/master Commit: 98bb3a8ab2c3c4be7f5a6027d081baea9590ae26 Parents: ae7b947 Author: sunlan <[email protected]> Authored: Wed Dec 6 16:32:36 2017 +0800 Committer: sunlan <[email protected]> Committed: Wed Dec 6 16:32:36 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/98bb3a8a/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() {
