OSDN Git Service

Fixed StringBuilder allocating when appending another StringBuilder. Stupid harmony!
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 17 Jul 2012 01:47:23 +0000 (01:47 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Tue, 17 Jul 2012 01:47:23 +0000 (01:47 +0000)
gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Label.java
gdx/src/com/badlogic/gdx/utils/StringBuilder.java

index a303065..c413987 100644 (file)
@@ -88,12 +88,14 @@ public class Label extends Widget {
        public void setText (CharSequence newText) {\r
                if (newText instanceof StringBuilder) {\r
                        if (text.equals(newText)) return;\r
+                       text.setLength(0);\r
+                       text.append((StringBuilder)newText);\r
                } else {\r
                        if (newText == null) newText = "";\r
                        if (isEqual(text.chars, newText)) return;\r
+                       text.setLength(0);\r
+                       text.append(newText);\r
                }\r
-               text.setLength(0);\r
-               text.append(newText);\r
                computeBounds();\r
                invalidateHierarchy();\r
        }\r
index 66bec43..62739fa 100644 (file)
@@ -65,6 +65,12 @@ public class StringBuilder implements Appendable, CharSequence {
                this(seq.toString());\r
        }\r
 \r
+       public StringBuilder (StringBuilder builder) {\r
+               length = builder.length;\r
+               chars = new char[length + INITIAL_CAPACITY];\r
+               System.arraycopy(builder.chars, 0, chars, 0, length);\r
+       }\r
+\r
        /** Constructs an instance that's initialized with the contents of the specified {@code String}. The capacity of the new builder\r
         * will be the length of the {@code String} plus 16.\r
         * \r
@@ -804,6 +810,14 @@ public class StringBuilder implements Appendable, CharSequence {
                return this;\r
        }\r
 \r
+       public StringBuilder append (StringBuilder builder) {\r
+               if (builder == null)\r
+                       appendNull();\r
+               else\r
+                       append0(builder.chars, 0, builder.length);\r
+               return this;\r
+       }\r
+\r
        /** Appends the string representation of the specified subsequence of the {@code CharSequence}. If the {@code CharSequence} is\r
         * {@code null}, then the string {@code "null"} is used to extract the subsequence from.\r
         * \r
@@ -818,6 +832,14 @@ public class StringBuilder implements Appendable, CharSequence {
                return this;\r
        }\r
 \r
+       public StringBuilder append (StringBuilder builder, int start, int end) {\r
+               if (builder == null)\r
+                       appendNull();\r
+               else\r
+                       append0(builder.chars, start, end);\r
+               return this;\r
+       }\r
+\r
        /** Appends the encoded Unicode code point. The code point is converted to a {@code char[]} as defined by\r
         * {@link Character#toChars(int)}.\r
         * \r