author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 34326 | 2bb3b3aea3c5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
2 |
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
28 |
import java.util.Arrays; |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
29 |
import jdk.internal.HotSpotIntrinsicCandidate; |
2 | 30 |
|
31 |
/** |
|
32 |
* A thread-safe, mutable sequence of characters. |
|
33 |
* A string buffer is like a {@link String}, but can be modified. At any |
|
34 |
* point in time it contains some particular sequence of characters, but |
|
35 |
* the length and content of the sequence can be changed through certain |
|
36 |
* method calls. |
|
37 |
* <p> |
|
38 |
* String buffers are safe for use by multiple threads. The methods |
|
39 |
* are synchronized where necessary so that all the operations on any |
|
40 |
* particular instance behave as if they occur in some serial order |
|
41 |
* that is consistent with the order of the method calls made by each of |
|
42 |
* the individual threads involved. |
|
43 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
44 |
* The principal operations on a {@code StringBuffer} are the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
45 |
* {@code append} and {@code insert} methods, which are |
2 | 46 |
* overloaded so as to accept data of any type. Each effectively |
47 |
* converts a given datum to a string and then appends or inserts the |
|
48 |
* characters of that string to the string buffer. The |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
49 |
* {@code append} method always adds these characters at the end |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
50 |
* of the buffer; the {@code insert} method adds the characters at |
2 | 51 |
* a specified point. |
52 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
53 |
* For example, if {@code z} refers to a string buffer object |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
54 |
* whose current contents are {@code "start"}, then |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
55 |
* the method call {@code z.append("le")} would cause the string |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
56 |
* buffer to contain {@code "startle"}, whereas |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
57 |
* {@code z.insert(4, "le")} would alter the string buffer to |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
58 |
* contain {@code "starlet"}. |
2 | 59 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
60 |
* In general, if sb refers to an instance of a {@code StringBuffer}, |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
61 |
* then {@code sb.append(x)} has the same effect as |
14997 | 62 |
* {@code sb.insert(sb.length(), x)}. |
2 | 63 |
* <p> |
64 |
* Whenever an operation occurs involving a source sequence (such as |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
65 |
* appending or inserting from a source sequence), this class synchronizes |
2 | 66 |
* only on the string buffer performing the operation, not on the source. |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
67 |
* Note that while {@code StringBuffer} is designed to be safe to use |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
68 |
* concurrently from multiple threads, if the constructor or the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
69 |
* {@code append} or {@code insert} operation is passed a source sequence |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
70 |
* that is shared across threads, the calling code must ensure |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
71 |
* that the operation has a consistent and unchanging view of the source |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
72 |
* sequence for the duration of the operation. |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
73 |
* This could be satisfied by the caller holding a lock during the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
74 |
* operation's call, by using an immutable source sequence, or by not |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
75 |
* sharing the source sequence across threads. |
2 | 76 |
* <p> |
77 |
* Every string buffer has a capacity. As long as the length of the |
|
78 |
* character sequence contained in the string buffer does not exceed |
|
79 |
* the capacity, it is not necessary to allocate a new internal |
|
80 |
* buffer array. If the internal buffer overflows, it is |
|
81 |
* automatically made larger. |
|
15312
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
82 |
* <p> |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
83 |
* Unless otherwise noted, passing a {@code null} argument to a constructor |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
84 |
* or method in this class will cause a {@link NullPointerException} to be |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
85 |
* thrown. |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
86 |
* <p> |
2 | 87 |
* As of release JDK 5, this class has been supplemented with an equivalent |
88 |
* class designed for use by a single thread, {@link StringBuilder}. The |
|
14997 | 89 |
* {@code StringBuilder} class should generally be used in preference to |
2 | 90 |
* this one, as it supports all of the same operations but it is faster, as |
91 |
* it performs no synchronization. |
|
92 |
* |
|
93 |
* @author Arthur van Hoff |
|
94 |
* @see java.lang.StringBuilder |
|
95 |
* @see java.lang.String |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
17709
diff
changeset
|
96 |
* @since 1.0 |
2 | 97 |
*/ |
98 |
public final class StringBuffer |
|
99 |
extends AbstractStringBuilder |
|
100 |
implements java.io.Serializable, CharSequence |
|
101 |
{ |
|
102 |
||
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
103 |
/** |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
104 |
* A cache of the last value returned by toString. Cleared |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
105 |
* whenever the StringBuffer is modified. |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
106 |
*/ |
33663 | 107 |
private transient String toStringCache; |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
108 |
|
2 | 109 |
/** use serialVersionUID from JDK 1.0.2 for interoperability */ |
110 |
static final long serialVersionUID = 3388685877147921107L; |
|
111 |
||
112 |
/** |
|
113 |
* Constructs a string buffer with no characters in it and an |
|
114 |
* initial capacity of 16 characters. |
|
115 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
116 |
@HotSpotIntrinsicCandidate |
2 | 117 |
public StringBuffer() { |
118 |
super(16); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Constructs a string buffer with no characters in it and |
|
123 |
* the specified initial capacity. |
|
124 |
* |
|
125 |
* @param capacity the initial capacity. |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
126 |
* @exception NegativeArraySizeException if the {@code capacity} |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
127 |
* argument is less than {@code 0}. |
2 | 128 |
*/ |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
129 |
@HotSpotIntrinsicCandidate |
2 | 130 |
public StringBuffer(int capacity) { |
131 |
super(capacity); |
|
132 |
} |
|
133 |
||
134 |
/** |
|
135 |
* Constructs a string buffer initialized to the contents of the |
|
136 |
* specified string. The initial capacity of the string buffer is |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
137 |
* {@code 16} plus the length of the string argument. |
2 | 138 |
* |
139 |
* @param str the initial contents of the buffer. |
|
140 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
141 |
@HotSpotIntrinsicCandidate |
2 | 142 |
public StringBuffer(String str) { |
143 |
super(str.length() + 16); |
|
144 |
append(str); |
|
145 |
} |
|
146 |
||
147 |
/** |
|
148 |
* Constructs a string buffer that contains the same characters |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
149 |
* as the specified {@code CharSequence}. The initial capacity of |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
150 |
* the string buffer is {@code 16} plus the length of the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
151 |
* {@code CharSequence} argument. |
2 | 152 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
153 |
* If the length of the specified {@code CharSequence} is |
2 | 154 |
* less than or equal to zero, then an empty buffer of capacity |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
155 |
* {@code 16} is returned. |
2 | 156 |
* |
157 |
* @param seq the sequence to copy. |
|
158 |
* @since 1.5 |
|
159 |
*/ |
|
160 |
public StringBuffer(CharSequence seq) { |
|
161 |
this(seq.length() + 16); |
|
162 |
append(seq); |
|
163 |
} |
|
164 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
165 |
@Override |
2 | 166 |
public synchronized int length() { |
167 |
return count; |
|
168 |
} |
|
169 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
170 |
@Override |
2 | 171 |
public synchronized int capacity() { |
33663 | 172 |
return super.capacity(); |
2 | 173 |
} |
174 |
||
175 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
176 |
@Override |
2 | 177 |
public synchronized void ensureCapacity(int minimumCapacity) { |
33663 | 178 |
super.ensureCapacity(minimumCapacity); |
2 | 179 |
} |
180 |
||
181 |
/** |
|
182 |
* @since 1.5 |
|
183 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
184 |
@Override |
2 | 185 |
public synchronized void trimToSize() { |
186 |
super.trimToSize(); |
|
187 |
} |
|
188 |
||
189 |
/** |
|
190 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
191 |
* @see #length() |
|
192 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
193 |
@Override |
2 | 194 |
public synchronized void setLength(int newLength) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
195 |
toStringCache = null; |
2 | 196 |
super.setLength(newLength); |
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
201 |
* @see #length() |
|
202 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
203 |
@Override |
2 | 204 |
public synchronized char charAt(int index) { |
33663 | 205 |
return super.charAt(index); |
2 | 206 |
} |
207 |
||
208 |
/** |
|
29974
9dea25b5ffba
8048264: StringBuffer's codePoint methods throw unspecified IndexOutOfBoundsException
bchristi
parents:
25859
diff
changeset
|
209 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
2 | 210 |
* @since 1.5 |
211 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
212 |
@Override |
2 | 213 |
public synchronized int codePointAt(int index) { |
214 |
return super.codePointAt(index); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
29974
9dea25b5ffba
8048264: StringBuffer's codePoint methods throw unspecified IndexOutOfBoundsException
bchristi
parents:
25859
diff
changeset
|
218 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
2 | 219 |
* @since 1.5 |
220 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
221 |
@Override |
2 | 222 |
public synchronized int codePointBefore(int index) { |
223 |
return super.codePointBefore(index); |
|
224 |
} |
|
225 |
||
226 |
/** |
|
29974
9dea25b5ffba
8048264: StringBuffer's codePoint methods throw unspecified IndexOutOfBoundsException
bchristi
parents:
25859
diff
changeset
|
227 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
2 | 228 |
* @since 1.5 |
229 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
230 |
@Override |
2 | 231 |
public synchronized int codePointCount(int beginIndex, int endIndex) { |
232 |
return super.codePointCount(beginIndex, endIndex); |
|
233 |
} |
|
234 |
||
235 |
/** |
|
29974
9dea25b5ffba
8048264: StringBuffer's codePoint methods throw unspecified IndexOutOfBoundsException
bchristi
parents:
25859
diff
changeset
|
236 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
2 | 237 |
* @since 1.5 |
238 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
239 |
@Override |
2 | 240 |
public synchronized int offsetByCodePoints(int index, int codePointOffset) { |
241 |
return super.offsetByCodePoints(index, codePointOffset); |
|
242 |
} |
|
243 |
||
244 |
/** |
|
245 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
246 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
247 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
248 |
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, |
2 | 249 |
int dstBegin) |
250 |
{ |
|
251 |
super.getChars(srcBegin, srcEnd, dst, dstBegin); |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
256 |
* @see #length() |
|
257 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
258 |
@Override |
2 | 259 |
public synchronized void setCharAt(int index, char ch) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
260 |
toStringCache = null; |
33663 | 261 |
super.setCharAt(index, ch); |
2 | 262 |
} |
263 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
264 |
@Override |
2 | 265 |
public synchronized StringBuffer append(Object obj) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
266 |
toStringCache = null; |
2 | 267 |
super.append(String.valueOf(obj)); |
268 |
return this; |
|
269 |
} |
|
270 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
271 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
272 |
@HotSpotIntrinsicCandidate |
2 | 273 |
public synchronized StringBuffer append(String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
274 |
toStringCache = null; |
2 | 275 |
super.append(str); |
276 |
return this; |
|
277 |
} |
|
278 |
||
279 |
/** |
|
14997 | 280 |
* Appends the specified {@code StringBuffer} to this sequence. |
2 | 281 |
* <p> |
14997 | 282 |
* The characters of the {@code StringBuffer} argument are appended, |
283 |
* in order, to the contents of this {@code StringBuffer}, increasing the |
|
284 |
* length of this {@code StringBuffer} by the length of the argument. |
|
285 |
* If {@code sb} is {@code null}, then the four characters |
|
286 |
* {@code "null"} are appended to this {@code StringBuffer}. |
|
2 | 287 |
* <p> |
288 |
* Let <i>n</i> be the length of the old character sequence, the one |
|
14997 | 289 |
* contained in the {@code StringBuffer} just prior to execution of the |
290 |
* {@code append} method. Then the character at index <i>k</i> in |
|
2 | 291 |
* the new character sequence is equal to the character at index <i>k</i> |
292 |
* in the old character sequence, if <i>k</i> is less than <i>n</i>; |
|
293 |
* otherwise, it is equal to the character at index <i>k-n</i> in the |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
294 |
* argument {@code sb}. |
2 | 295 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
296 |
* This method synchronizes on {@code this}, the destination |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
297 |
* object, but does not synchronize on the source ({@code sb}). |
2 | 298 |
* |
14997 | 299 |
* @param sb the {@code StringBuffer} to append. |
2 | 300 |
* @return a reference to this object. |
301 |
* @since 1.4 |
|
302 |
*/ |
|
303 |
public synchronized StringBuffer append(StringBuffer sb) { |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
304 |
toStringCache = null; |
2 | 305 |
super.append(sb); |
306 |
return this; |
|
307 |
} |
|
308 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
309 |
/** |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
310 |
* @since 1.8 |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
311 |
*/ |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
312 |
@Override |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
313 |
synchronized StringBuffer append(AbstractStringBuilder asb) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
314 |
toStringCache = null; |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
315 |
super.append(asb); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
316 |
return this; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
317 |
} |
2 | 318 |
|
319 |
/** |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
320 |
* Appends the specified {@code CharSequence} to this |
2 | 321 |
* sequence. |
322 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
323 |
* The characters of the {@code CharSequence} argument are appended, |
2 | 324 |
* in order, increasing the length of this sequence by the length of the |
325 |
* argument. |
|
326 |
* |
|
327 |
* <p>The result of this method is exactly the same as if it were an |
|
328 |
* invocation of this.append(s, 0, s.length()); |
|
329 |
* |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
330 |
* <p>This method synchronizes on {@code this}, the destination |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
331 |
* object, but does not synchronize on the source ({@code s}). |
2 | 332 |
* |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
333 |
* <p>If {@code s} is {@code null}, then the four characters |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
334 |
* {@code "null"} are appended. |
2 | 335 |
* |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
336 |
* @param s the {@code CharSequence} to append. |
2 | 337 |
* @return a reference to this object. |
338 |
* @since 1.5 |
|
339 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
340 |
@Override |
17709
fc6f678fdb83
8014814: (str) StringBuffer "null" is not appended
dholmes
parents:
17472
diff
changeset
|
341 |
public synchronized StringBuffer append(CharSequence s) { |
fc6f678fdb83
8014814: (str) StringBuffer "null" is not appended
dholmes
parents:
17472
diff
changeset
|
342 |
toStringCache = null; |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
343 |
super.append(s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
344 |
return this; |
2 | 345 |
} |
346 |
||
347 |
/** |
|
348 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
349 |
* @since 1.5 |
|
350 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
351 |
@Override |
2 | 352 |
public synchronized StringBuffer append(CharSequence s, int start, int end) |
353 |
{ |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
354 |
toStringCache = null; |
2 | 355 |
super.append(s, start, end); |
356 |
return this; |
|
357 |
} |
|
358 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
359 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
360 |
public synchronized StringBuffer append(char[] str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
361 |
toStringCache = null; |
2 | 362 |
super.append(str); |
363 |
return this; |
|
364 |
} |
|
365 |
||
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
366 |
/** |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
367 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
368 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
369 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
370 |
public synchronized StringBuffer append(char[] str, int offset, int len) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
371 |
toStringCache = null; |
2 | 372 |
super.append(str, offset, len); |
373 |
return this; |
|
374 |
} |
|
375 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
376 |
@Override |
2 | 377 |
public synchronized StringBuffer append(boolean b) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
378 |
toStringCache = null; |
2 | 379 |
super.append(b); |
380 |
return this; |
|
381 |
} |
|
382 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
383 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
384 |
@HotSpotIntrinsicCandidate |
2 | 385 |
public synchronized StringBuffer append(char c) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
386 |
toStringCache = null; |
2 | 387 |
super.append(c); |
388 |
return this; |
|
389 |
} |
|
390 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
391 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
392 |
@HotSpotIntrinsicCandidate |
2 | 393 |
public synchronized StringBuffer append(int i) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
394 |
toStringCache = null; |
2 | 395 |
super.append(i); |
396 |
return this; |
|
397 |
} |
|
398 |
||
399 |
/** |
|
400 |
* @since 1.5 |
|
401 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
402 |
@Override |
2 | 403 |
public synchronized StringBuffer appendCodePoint(int codePoint) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
404 |
toStringCache = null; |
2 | 405 |
super.appendCodePoint(codePoint); |
406 |
return this; |
|
407 |
} |
|
408 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
409 |
@Override |
2 | 410 |
public synchronized StringBuffer append(long lng) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
411 |
toStringCache = null; |
2 | 412 |
super.append(lng); |
413 |
return this; |
|
414 |
} |
|
415 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
416 |
@Override |
2 | 417 |
public synchronized StringBuffer append(float f) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
418 |
toStringCache = null; |
2 | 419 |
super.append(f); |
420 |
return this; |
|
421 |
} |
|
422 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
423 |
@Override |
2 | 424 |
public synchronized StringBuffer append(double d) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
425 |
toStringCache = null; |
2 | 426 |
super.append(d); |
427 |
return this; |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
432 |
* @since 1.2 |
|
433 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
434 |
@Override |
2 | 435 |
public synchronized StringBuffer delete(int start, int end) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
436 |
toStringCache = null; |
2 | 437 |
super.delete(start, end); |
438 |
return this; |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
443 |
* @since 1.2 |
|
444 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
445 |
@Override |
2 | 446 |
public synchronized StringBuffer deleteCharAt(int index) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
447 |
toStringCache = null; |
2 | 448 |
super.deleteCharAt(index); |
449 |
return this; |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
454 |
* @since 1.2 |
|
455 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
456 |
@Override |
2 | 457 |
public synchronized StringBuffer replace(int start, int end, String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
458 |
toStringCache = null; |
2 | 459 |
super.replace(start, end, str); |
460 |
return this; |
|
461 |
} |
|
462 |
||
463 |
/** |
|
464 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
465 |
* @since 1.2 |
|
466 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
467 |
@Override |
2 | 468 |
public synchronized String substring(int start) { |
469 |
return substring(start, count); |
|
470 |
} |
|
471 |
||
472 |
/** |
|
473 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
474 |
* @since 1.4 |
|
475 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
476 |
@Override |
2 | 477 |
public synchronized CharSequence subSequence(int start, int end) { |
478 |
return super.substring(start, end); |
|
479 |
} |
|
480 |
||
481 |
/** |
|
482 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
483 |
* @since 1.2 |
|
484 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
485 |
@Override |
2 | 486 |
public synchronized String substring(int start, int end) { |
487 |
return super.substring(start, end); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
491 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
492 |
* @since 1.2 |
|
493 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
494 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
495 |
public synchronized StringBuffer insert(int index, char[] str, int offset, |
2 | 496 |
int len) |
497 |
{ |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
498 |
toStringCache = null; |
2 | 499 |
super.insert(index, str, offset, len); |
500 |
return this; |
|
501 |
} |
|
502 |
||
503 |
/** |
|
504 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
505 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
506 |
@Override |
2 | 507 |
public synchronized StringBuffer insert(int offset, Object obj) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
508 |
toStringCache = null; |
2 | 509 |
super.insert(offset, String.valueOf(obj)); |
510 |
return this; |
|
511 |
} |
|
512 |
||
513 |
/** |
|
514 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
515 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
516 |
@Override |
2 | 517 |
public synchronized StringBuffer insert(int offset, String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
518 |
toStringCache = null; |
2 | 519 |
super.insert(offset, str); |
520 |
return this; |
|
521 |
} |
|
522 |
||
523 |
/** |
|
524 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
525 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
526 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
527 |
public synchronized StringBuffer insert(int offset, char[] str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
528 |
toStringCache = null; |
2 | 529 |
super.insert(offset, str); |
530 |
return this; |
|
531 |
} |
|
532 |
||
533 |
/** |
|
534 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
535 |
* @since 1.5 |
|
536 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
537 |
@Override |
2 | 538 |
public StringBuffer insert(int dstOffset, CharSequence s) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
539 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
540 |
// after narrowing of s to specific type |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
541 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
542 |
super.insert(dstOffset, s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
543 |
return this; |
2 | 544 |
} |
545 |
||
546 |
/** |
|
547 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
548 |
* @since 1.5 |
|
549 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
550 |
@Override |
2 | 551 |
public synchronized StringBuffer insert(int dstOffset, CharSequence s, |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
552 |
int start, int end) |
2 | 553 |
{ |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
554 |
toStringCache = null; |
2 | 555 |
super.insert(dstOffset, s, start, end); |
556 |
return this; |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
561 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
562 |
@Override |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
563 |
public StringBuffer insert(int offset, boolean b) { |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
564 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
565 |
// after conversion of b to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
566 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
567 |
super.insert(offset, b); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
568 |
return this; |
2 | 569 |
} |
570 |
||
571 |
/** |
|
572 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
573 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
574 |
@Override |
2 | 575 |
public synchronized StringBuffer insert(int offset, char c) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
576 |
toStringCache = null; |
2 | 577 |
super.insert(offset, c); |
578 |
return this; |
|
579 |
} |
|
580 |
||
581 |
/** |
|
582 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
583 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
584 |
@Override |
2 | 585 |
public StringBuffer insert(int offset, int i) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
586 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
587 |
// after conversion of i to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
588 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
589 |
super.insert(offset, i); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
590 |
return this; |
2 | 591 |
} |
592 |
||
593 |
/** |
|
594 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
595 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
596 |
@Override |
2 | 597 |
public StringBuffer insert(int offset, long l) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
598 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
599 |
// after conversion of l to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
600 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
601 |
super.insert(offset, l); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
602 |
return this; |
2 | 603 |
} |
604 |
||
605 |
/** |
|
606 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
607 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
608 |
@Override |
2 | 609 |
public StringBuffer insert(int offset, float f) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
610 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
611 |
// after conversion of f to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
612 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
613 |
super.insert(offset, f); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
614 |
return this; |
2 | 615 |
} |
616 |
||
617 |
/** |
|
618 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
619 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
620 |
@Override |
2 | 621 |
public StringBuffer insert(int offset, double d) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
622 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
623 |
// after conversion of d to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
624 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
625 |
super.insert(offset, d); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
626 |
return this; |
2 | 627 |
} |
628 |
||
629 |
/** |
|
630 |
* @since 1.4 |
|
631 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
632 |
@Override |
2 | 633 |
public int indexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
634 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
635 |
return super.indexOf(str); |
2 | 636 |
} |
637 |
||
638 |
/** |
|
639 |
* @since 1.4 |
|
640 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
641 |
@Override |
2 | 642 |
public synchronized int indexOf(String str, int fromIndex) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
643 |
return super.indexOf(str, fromIndex); |
2 | 644 |
} |
645 |
||
646 |
/** |
|
647 |
* @since 1.4 |
|
648 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
649 |
@Override |
2 | 650 |
public int lastIndexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
651 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
2 | 652 |
return lastIndexOf(str, count); |
653 |
} |
|
654 |
||
655 |
/** |
|
656 |
* @since 1.4 |
|
657 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
658 |
@Override |
2 | 659 |
public synchronized int lastIndexOf(String str, int fromIndex) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
660 |
return super.lastIndexOf(str, fromIndex); |
2 | 661 |
} |
662 |
||
663 |
/** |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
17709
diff
changeset
|
664 |
* @since 1.0.2 |
2 | 665 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
666 |
@Override |
2 | 667 |
public synchronized StringBuffer reverse() { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
668 |
toStringCache = null; |
2 | 669 |
super.reverse(); |
670 |
return this; |
|
671 |
} |
|
672 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
673 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
29974
diff
changeset
|
674 |
@HotSpotIntrinsicCandidate |
2 | 675 |
public synchronized String toString() { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
676 |
if (toStringCache == null) { |
33663 | 677 |
return toStringCache = |
678 |
isLatin1() ? StringLatin1.newString(value, 0, count) |
|
679 |
: StringUTF16.newString(value, 0, count); |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
680 |
} |
33663 | 681 |
return new String(toStringCache); |
2 | 682 |
} |
683 |
||
684 |
/** |
|
685 |
* Serializable fields for StringBuffer. |
|
686 |
* |
|
687 |
* @serialField value char[] |
|
688 |
* The backing character array of this StringBuffer. |
|
689 |
* @serialField count int |
|
690 |
* The number of characters in this StringBuffer. |
|
691 |
* @serialField shared boolean |
|
692 |
* A flag indicating whether the backing array is shared. |
|
693 |
* The value is ignored upon deserialization. |
|
694 |
*/ |
|
695 |
private static final java.io.ObjectStreamField[] serialPersistentFields = |
|
696 |
{ |
|
697 |
new java.io.ObjectStreamField("value", char[].class), |
|
698 |
new java.io.ObjectStreamField("count", Integer.TYPE), |
|
699 |
new java.io.ObjectStreamField("shared", Boolean.TYPE), |
|
700 |
}; |
|
701 |
||
702 |
/** |
|
703 |
* readObject is called to restore the state of the StringBuffer from |
|
704 |
* a stream. |
|
705 |
*/ |
|
706 |
private synchronized void writeObject(java.io.ObjectOutputStream s) |
|
707 |
throws java.io.IOException { |
|
708 |
java.io.ObjectOutputStream.PutField fields = s.putFields(); |
|
33663 | 709 |
char[] val = new char[capacity()]; |
710 |
if (isLatin1()) { |
|
711 |
StringLatin1.getChars(value, 0, count, val, 0); |
|
712 |
} else { |
|
713 |
StringUTF16.getChars(value, 0, count, val, 0); |
|
714 |
} |
|
715 |
fields.put("value", val); |
|
2 | 716 |
fields.put("count", count); |
717 |
fields.put("shared", false); |
|
718 |
s.writeFields(); |
|
719 |
} |
|
720 |
||
721 |
/** |
|
722 |
* readObject is called to restore the state of the StringBuffer from |
|
723 |
* a stream. |
|
724 |
*/ |
|
725 |
private void readObject(java.io.ObjectInputStream s) |
|
726 |
throws java.io.IOException, ClassNotFoundException { |
|
727 |
java.io.ObjectInputStream.GetField fields = s.readFields(); |
|
33663 | 728 |
char[] val = (char[])fields.get("value", null); |
729 |
initBytes(val, 0, val.length); |
|
2 | 730 |
count = fields.get("count", 0); |
731 |
} |
|
33663 | 732 |
|
34326
2bb3b3aea3c5
8143553: StringBuffer.getByte(byte[], int, byte) should be package private (not protected)
sherman
parents:
33663
diff
changeset
|
733 |
synchronized void getBytes(byte dst[], int dstBegin, byte coder) { |
33663 | 734 |
super.getBytes(dst, dstBegin, coder); |
735 |
} |
|
2 | 736 |
} |