src/share/classes/java/lang/StringBuffer.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
jdk Cdiff src/share/classes/java/lang/StringBuffer.java
src/share/classes/java/lang/StringBuffer.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 96,105 ****
--- 96,111 ----
public final class StringBuffer
extends AbstractStringBuilder
implements java.io.Serializable, CharSequence
{
+ /**
+ * A cache of the last value returned by toString. Cleared
+ * whenever the StringBuffer is modified.
+ */
+ private transient String toStringCache;
+
/** use serialVersionUID from JDK 1.0.2 for interoperability */
static final long serialVersionUID = 3388685877147921107L;
/**
* Constructs a string buffer with no characters in it and an
*** 182,191 ****
--- 188,198 ----
* @see #length()
*/
@Override
public synchronized void setLength(int newLength) {
super.setLength(newLength);
+ toStringCache = null;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*** 246,266 ****
--- 253,276 ----
@Override
public synchronized void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
value[index] = ch;
+ toStringCache = null;
}
@Override
public synchronized StringBuffer append(Object obj) {
super.append(String.valueOf(obj));
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(String str) {
super.append(str);
+ toStringCache = null;
return this;
}
/**
* Appends the specified {@code StringBuffer} to this sequence.
*** 286,304 ****
--- 296,316 ----
* @return a reference to this object.
* @since 1.4
*/
public synchronized StringBuffer append(StringBuffer sb) {
super.append(sb);
+ toStringCache = null;
return this;
}
/**
* @since 1.8
*/
@Override
synchronized StringBuffer append(AbstractStringBuilder asb) {
super.append(asb);
+ toStringCache = null;
return this;
}
/**
* Appends the specified {@code CharSequence} to this
*** 323,332 ****
--- 335,345 ----
*/
@Override
public StringBuffer append(CharSequence s) {
// Note, synchronization achieved via invocations of other StringBuffer methods after
// narrowing of s to specific type
+ // Ditto for toStringCache clearing
super.append(s);
return this;
}
/**
*** 335,434 ****
--- 348,460 ----
*/
@Override
public synchronized StringBuffer append(CharSequence s, int start, int end)
{
super.append(s, start, end);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(char[] str) {
super.append(str);
+ toStringCache = null;
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized StringBuffer append(char[] str, int offset, int len) {
super.append(str, offset, len);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(boolean b) {
super.append(b);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(char c) {
super.append(c);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(int i) {
super.append(i);
+ toStringCache = null;
return this;
}
/**
* @since 1.5
*/
@Override
public synchronized StringBuffer appendCodePoint(int codePoint) {
super.appendCodePoint(codePoint);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(long lng) {
super.append(lng);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(float f) {
super.append(f);
+ toStringCache = null;
return this;
}
@Override
public synchronized StringBuffer append(double d) {
super.append(d);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
@Override
public synchronized StringBuffer delete(int start, int end) {
super.delete(start, end);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
@Override
public synchronized StringBuffer deleteCharAt(int index) {
super.deleteCharAt(index);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
@Override
public synchronized StringBuffer replace(int start, int end, String str) {
super.replace(start, end, str);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*** 464,500 ****
--- 490,530 ----
@Override
public synchronized StringBuffer insert(int index, char[] str, int offset,
int len)
{
super.insert(index, str, offset, len);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized StringBuffer insert(int offset, Object obj) {
super.insert(offset, String.valueOf(obj));
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized StringBuffer insert(int offset, String str) {
super.insert(offset, str);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized StringBuffer insert(int offset, char[] str) {
super.insert(offset, str);
+ toStringCache = null;
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*** 502,511 ****
--- 532,542 ----
*/
@Override
public StringBuffer insert(int dstOffset, CharSequence s) {
// Note, synchronization achieved via invocations of other StringBuffer methods
// after narrowing of s to specific type
+ // Ditto for toStringCache clearing
super.insert(dstOffset, s);
return this;
}
/**
*** 515,554 ****
--- 546,589 ----
@Override
public synchronized StringBuffer insert(int dstOffset, CharSequence s,
int start, int end)
{
super.insert(dstOffset, s, start, end);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
@Override
public StringBuffer insert(int offset, boolean b) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of b to String by super class method
+ // Ditto for toStringCache clearing
super.insert(offset, b);
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized StringBuffer insert(int offset, char c) {
super.insert(offset, c);
+ toStringCache = null;
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
@Override
public StringBuffer insert(int offset, int i) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of i to String by super class method
+ // Ditto for toStringCache clearing
super.insert(offset, i);
return this;
}
/**
*** 556,565 ****
--- 591,601 ----
*/
@Override
public StringBuffer insert(int offset, long l) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of l to String by super class method
+ // Ditto for toStringCache clearing
super.insert(offset, l);
return this;
}
/**
*** 567,576 ****
--- 603,613 ----
*/
@Override
public StringBuffer insert(int offset, float f) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of f to String by super class method
+ // Ditto for toStringCache clearing
super.insert(offset, f);
return this;
}
/**
*** 578,587 ****
--- 615,625 ----
*/
@Override
public StringBuffer insert(int offset, double d) {
// Note, synchronization achieved via invocation of StringBuffer insert(int, String)
// after conversion of d to String by super class method
+ // Ditto for toStringCache clearing
super.insert(offset, d);
return this;
}
/**
*** 622,637 ****
* @since JDK1.0.2
*/
@Override
public synchronized StringBuffer reverse() {
super.reverse();
return this;
}
@Override
public synchronized String toString() {
! return new String(value, 0, count);
}
/**
* Serializable fields for StringBuffer.
*
--- 660,681 ----
* @since JDK1.0.2
*/
@Override
public synchronized StringBuffer reverse() {
super.reverse();
+ toStringCache = null;
return this;
}
@Override
public synchronized String toString() {
! if (toStringCache == null) {
! toStringCache = new String(value, 0, count);
! return toStringCache;
! } else {
! return new String(toStringCache);
! }
}
/**
* Serializable fields for StringBuffer.
*
src/share/classes/java/lang/StringBuffer.java
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File