提交 86c8c165 编写于 作者: R rupashka

6432566: Replace usage of StringBuffer with StringBuilder in Swing

Reviewed-by: malenkov
上级 ea742e00
...@@ -1322,13 +1322,11 @@ public class DebugGraphics extends Graphics { ...@@ -1322,13 +1322,11 @@ public class DebugGraphics extends Graphics {
} }
String toShortString() { String toShortString() {
StringBuffer buffer = new StringBuffer("Graphics" + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID + "-" + debugOptions + ")"); return "Graphics" + (isDrawingBuffer() ? "<B>" : "") + "(" + graphicsID + "-" + debugOptions + ")";
return buffer.toString();
} }
String pointToString(int x, int y) { String pointToString(int x, int y) {
StringBuffer buffer = new StringBuffer("(" + x + ", " + y + ")"); return "(" + x + ", " + y + ")";
return buffer.toString();
} }
/** Enables/disables diagnostic information about every graphics /** Enables/disables diagnostic information about every graphics
......
...@@ -1334,13 +1334,13 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou ...@@ -1334,13 +1334,13 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
&& component.getClientProperty("JPasswordField.cutCopyAllowed") != && component.getClientProperty("JPasswordField.cutCopyAllowed") !=
Boolean.TRUE) { Boolean.TRUE) {
//fix for 4793761 //fix for 4793761
StringBuffer txt = null; StringBuilder txt = null;
char echoChar = ((JPasswordField)component).getEchoChar(); char echoChar = ((JPasswordField)component).getEchoChar();
int p0 = Math.min(getDot(), getMark()); int p0 = Math.min(getDot(), getMark());
int p1 = Math.max(getDot(), getMark()); int p1 = Math.max(getDot(), getMark());
for (int i = p0; i < p1; i++) { for (int i = p0; i < p1; i++) {
if (txt == null) { if (txt == null) {
txt = new StringBuffer(); txt = new StringBuilder();
} }
txt.append(echoChar); txt.append(echoChar);
} }
...@@ -1675,7 +1675,6 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou ...@@ -1675,7 +1675,6 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
} }
return; return;
} }
int adjust = 0;
int offset = e.getOffset(); int offset = e.getOffset();
int length = e.getLength(); int length = e.getLength();
int newDot = dot; int newDot = dot;
...@@ -1759,7 +1758,6 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou ...@@ -1759,7 +1758,6 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
} }
int offs0 = e.getOffset(); int offs0 = e.getOffset();
int offs1 = offs0 + e.getLength(); int offs1 = offs0 + e.getLength();
int adjust = 0;
int newDot = dot; int newDot = dot;
boolean adjustDotBias = false; boolean adjustDotBias = false;
int newMark = mark; int newMark = mark;
......
...@@ -132,7 +132,7 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDoc ...@@ -132,7 +132,7 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDoc
// install the content // install the content
Content c = getContent(); Content c = getContent();
int n = data.length; int n = data.length;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
ElementSpec es = data[i]; ElementSpec es = data[i];
if (es.getLength() > 0) { if (es.getLength() > 0) {
...@@ -191,7 +191,7 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDoc ...@@ -191,7 +191,7 @@ public class DefaultStyledDocument extends AbstractDocument implements StyledDoc
// install the content // install the content
Content c = getContent(); Content c = getContent();
int n = data.length; int n = data.length;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
ElementSpec es = data[i]; ElementSpec es = data[i];
if (es.getLength() > 0) { if (es.getLength() > 0) {
......
...@@ -30,7 +30,6 @@ import java.text.*; ...@@ -30,7 +30,6 @@ import java.text.*;
import java.text.AttributedCharacterIterator.Attribute; import java.text.AttributedCharacterIterator.Attribute;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*;
/** /**
* <code>InternationalFormatter</code> extends <code>DefaultFormatter</code>, * <code>InternationalFormatter</code> extends <code>DefaultFormatter</code>,
...@@ -875,7 +874,6 @@ public class InternationalFormatter extends DefaultFormatter { ...@@ -875,7 +874,6 @@ public class InternationalFormatter extends DefaultFormatter {
(f instanceof AttributedCharacterIterator.Attribute)) { (f instanceof AttributedCharacterIterator.Attribute)) {
AttributedCharacterIterator.Attribute field = AttributedCharacterIterator.Attribute field =
(AttributedCharacterIterator.Attribute)f; (AttributedCharacterIterator.Attribute)f;
int index = 0;
iterator.first(); iterator.first();
while (iterator.getIndex() < start) { while (iterator.getIndex() < start) {
......
...@@ -35,10 +35,7 @@ import java.util.HashMap; ...@@ -35,10 +35,7 @@ import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.*; import java.util.concurrent.*;
...@@ -4058,7 +4055,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A ...@@ -4058,7 +4055,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
private static final Object KEYMAP_TABLE = private static final Object KEYMAP_TABLE =
new StringBuilder("JTextComponent_KeymapTable"); new StringBuilder("JTextComponent_KeymapTable");
private JTextComponent editor;
// //
// member variables used for on-the-spot input method // member variables used for on-the-spot input method
// editing style support // editing style support
...@@ -4748,14 +4745,14 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A ...@@ -4748,14 +4745,14 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
processKeyEvent(ke); processKeyEvent(ke);
} }
} else { } else {
StringBuffer strBuf = new StringBuffer(); StringBuilder strBuf = new StringBuilder();
for (char c = text.current(); commitCount > 0; for (char c = text.current(); commitCount > 0;
c = text.next(), commitCount--) { c = text.next(), commitCount--) {
strBuf.append(c); strBuf.append(c);
} }
// map it to an ActionEvent // map it to an ActionEvent
mapCommittedTextToAction(new String(strBuf)); mapCommittedTextToAction(strBuf.toString());
} }
// Remember latest committed text end index // Remember latest committed text end index
...@@ -4801,7 +4798,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A ...@@ -4801,7 +4798,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
private void createComposedTextAttribute(int composedIndex, private void createComposedTextAttribute(int composedIndex,
AttributedCharacterIterator text) { AttributedCharacterIterator text) {
Document doc = getDocument(); Document doc = getDocument();
StringBuffer strBuf = new StringBuffer(); StringBuilder strBuf = new StringBuilder();
// create attributed string with no attributes // create attributed string with no attributes
for (char c = text.setIndex(composedIndex); for (char c = text.setIndex(composedIndex);
...@@ -4809,7 +4806,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A ...@@ -4809,7 +4806,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
strBuf.append(c); strBuf.append(c);
} }
composedTextContent = new String(strBuf); composedTextContent = strBuf.toString();
composedTextAttribute = new SimpleAttributeSet(); composedTextAttribute = new SimpleAttributeSet();
composedTextAttribute.addAttribute(StyleConstants.ComposedTextAttribute, composedTextAttribute.addAttribute(StyleConstants.ComposedTextAttribute,
new AttributedString(text, composedIndex, text.getEndIndex())); new AttributedString(text, composedIndex, text.getEndIndex()));
......
...@@ -29,7 +29,6 @@ import java.io.*; ...@@ -29,7 +29,6 @@ import java.io.*;
import java.text.*; import java.text.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*;
/** /**
* <code>MaskFormatter</code> is used to format and edit strings. The behavior * <code>MaskFormatter</code> is used to format and edit strings. The behavior
...@@ -385,7 +384,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -385,7 +384,7 @@ public class MaskFormatter extends DefaultFormatter {
*/ */
public String valueToString(Object value) throws ParseException { public String valueToString(Object value) throws ParseException {
String sValue = (value == null) ? "" : value.toString(); String sValue = (value == null) ? "" : value.toString();
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
String placeholder = getPlaceholder(); String placeholder = getPlaceholder();
int[] valueCounter = { 0 }; int[] valueCounter = { 0 };
...@@ -484,7 +483,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -484,7 +483,7 @@ public class MaskFormatter extends DefaultFormatter {
* Invokes <code>append</code> on the mask characters in * Invokes <code>append</code> on the mask characters in
* <code>mask</code>. * <code>mask</code>.
*/ */
private void append(StringBuffer result, String value, int[] index, private void append(StringBuilder result, String value, int[] index,
String placeholder, MaskCharacter[] mask) String placeholder, MaskCharacter[] mask)
throws ParseException { throws ParseException {
for (int counter = 0, maxCounter = mask.length; for (int counter = 0, maxCounter = mask.length;
...@@ -611,13 +610,13 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -611,13 +610,13 @@ public class MaskFormatter extends DefaultFormatter {
* Removes the literal characters from the passed in string. * Removes the literal characters from the passed in string.
*/ */
private String stripLiteralChars(String string) { private String stripLiteralChars(String string) {
StringBuffer sb = null; StringBuilder sb = null;
int last = 0; int last = 0;
for (int counter = 0, max = string.length(); counter < max; counter++){ for (int counter = 0, max = string.length(); counter < max; counter++){
if (isLiteral(counter)) { if (isLiteral(counter)) {
if (sb == null) { if (sb == null) {
sb = new StringBuffer(); sb = new StringBuilder();
if (counter > 0) { if (counter > 0) {
sb.append(string.substring(0, counter)); sb.append(string.substring(0, counter));
} }
...@@ -715,10 +714,10 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -715,10 +714,10 @@ public class MaskFormatter extends DefaultFormatter {
*/ */
boolean canReplace(ReplaceHolder rh) { boolean canReplace(ReplaceHolder rh) {
// This method is rather long, but much of the burden is in // This method is rather long, but much of the burden is in
// maintaining a String and swapping to a StringBuffer only if // maintaining a String and swapping to a StringBuilder only if
// absolutely necessary. // absolutely necessary.
if (!getAllowsInvalid()) { if (!getAllowsInvalid()) {
StringBuffer replace = null; StringBuilder replace = null;
String text = rh.text; String text = rh.text;
int tl = (text != null) ? text.length() : 0; int tl = (text != null) ? text.length() : 0;
...@@ -737,7 +736,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -737,7 +736,7 @@ public class MaskFormatter extends DefaultFormatter {
char aChar = text.charAt(textIndex); char aChar = text.charAt(textIndex);
if (aChar != getCharacter(rh.offset + counter, aChar)) { if (aChar != getCharacter(rh.offset + counter, aChar)) {
if (replace == null) { if (replace == null) {
replace = new StringBuffer(); replace = new StringBuilder();
if (textIndex > 0) { if (textIndex > 0) {
replace.append(text.substring(0, textIndex)); replace.append(text.substring(0, textIndex));
} }
...@@ -758,7 +757,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -758,7 +757,7 @@ public class MaskFormatter extends DefaultFormatter {
} }
} }
else if (textIndex > 0) { else if (textIndex > 0) {
replace = new StringBuffer(max); replace = new StringBuilder(max);
replace.append(text.substring(0, textIndex)); replace.append(text.substring(0, textIndex));
replace.append(getLiteral(rh.offset + counter)); replace.append(getLiteral(rh.offset + counter));
if (textIndex < tl) { if (textIndex < tl) {
...@@ -780,7 +779,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -780,7 +779,7 @@ public class MaskFormatter extends DefaultFormatter {
else if (textIndex >= tl) { else if (textIndex >= tl) {
// placeholder // placeholder
if (replace == null) { if (replace == null) {
replace = new StringBuffer(); replace = new StringBuilder();
if (text != null) { if (text != null) {
replace.append(text); replace.append(text);
} }
...@@ -863,7 +862,7 @@ public class MaskFormatter extends DefaultFormatter { ...@@ -863,7 +862,7 @@ public class MaskFormatter extends DefaultFormatter {
* Appends the necessary character in <code>formatting</code> at * Appends the necessary character in <code>formatting</code> at
* <code>index</code> to <code>buff</code>. * <code>index</code> to <code>buff</code>.
*/ */
public void append(StringBuffer buff, String formatting, int[] index, public void append(StringBuilder buff, String formatting, int[] index,
String placeholder) String placeholder)
throws ParseException { throws ParseException {
boolean inString = index[0] < formatting.length(); boolean inString = index[0] < formatting.length();
......
...@@ -27,7 +27,6 @@ package javax.swing.text; ...@@ -27,7 +27,6 @@ package javax.swing.text;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.text.*; import java.text.*;
import java.util.*; import java.util.*;
import javax.swing.text.*;
/** /**
* <code>NumberFormatter</code> subclasses <code>InternationalFormatter</code> * <code>NumberFormatter</code> subclasses <code>InternationalFormatter</code>
...@@ -132,7 +131,7 @@ public class NumberFormatter extends InternationalFormatter { ...@@ -132,7 +131,7 @@ public class NumberFormatter extends InternationalFormatter {
DecimalFormatSymbols dfs = getDecimalFormatSymbols(); DecimalFormatSymbols dfs = getDecimalFormatSymbols();
if (dfs != null) { if (dfs != null) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append(dfs.getCurrencySymbol()); sb.append(dfs.getCurrencySymbol());
sb.append(dfs.getDecimalSeparator()); sb.append(dfs.getDecimalSeparator());
...@@ -239,13 +238,6 @@ public class NumberFormatter extends InternationalFormatter { ...@@ -239,13 +238,6 @@ public class NumberFormatter extends InternationalFormatter {
return null; return null;
} }
/**
*/
private boolean isValidInsertionCharacter(char aChar) {
return (Character.isDigit(aChar) || specialChars.indexOf(aChar) != -1);
}
/** /**
* Subclassed to return false if <code>text</code> contains in an invalid * Subclassed to return false if <code>text</code> contains in an invalid
* character to insert, that is, it is not a digit * character to insert, that is, it is not a digit
...@@ -402,28 +394,6 @@ public class NumberFormatter extends InternationalFormatter { ...@@ -402,28 +394,6 @@ public class NumberFormatter extends InternationalFormatter {
return false; return false;
} }
/**
* Returns true if the range offset to length identifies the only
* integer field.
*/
private boolean isOnlyIntegerField(int offset, int length) {
if (isValidMask()) {
int start = getAttributeStart(NumberFormat.Field.INTEGER);
if (start != -1) {
AttributedCharacterIterator iterator = getIterator();
iterator.setIndex(start);
if (offset > start || iterator.getRunLimit(
NumberFormat.Field.INTEGER) > (offset + length)) {
return false;
}
return true;
}
}
return false;
}
/** /**
* Invoked to toggle the sign. For this to work the value class * Invoked to toggle the sign. For this to work the value class
* must have a single arg constructor that takes a String. * must have a single arg constructor that takes a String.
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package javax.swing.text; package javax.swing.text;
import java.util.Vector; import java.util.Vector;
import javax.swing.event.*;
/** /**
* A plain document that maintains no character attributes. The * A plain document that maintains no character attributes. The
...@@ -118,7 +117,7 @@ public class PlainDocument extends AbstractDocument { ...@@ -118,7 +117,7 @@ public class PlainDocument extends AbstractDocument {
Object filterNewlines = getProperty("filterNewlines"); Object filterNewlines = getProperty("filterNewlines");
if ((filterNewlines instanceof Boolean) && filterNewlines.equals(Boolean.TRUE)) { if ((filterNewlines instanceof Boolean) && filterNewlines.equals(Boolean.TRUE)) {
if ((str != null) && (str.indexOf('\n') >= 0)) { if ((str != null) && (str.indexOf('\n') >= 0)) {
StringBuffer filtered = new StringBuffer(str); StringBuilder filtered = new StringBuilder(str);
int n = filtered.length(); int n = filtered.length();
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (filtered.charAt(i) == '\n') { if (filtered.charAt(i) == '\n') {
...@@ -204,11 +203,9 @@ public class PlainDocument extends AbstractDocument { ...@@ -204,11 +203,9 @@ public class PlainDocument extends AbstractDocument {
} }
} }
if (hasBreaks) { if (hasBreaks) {
int rmCount = 1;
removed.addElement(rmCandidate); removed.addElement(rmCandidate);
if ((offset + length == rmOffs1) && (lastOffset != rmOffs1) && if ((offset + length == rmOffs1) && (lastOffset != rmOffs1) &&
((index+1) < lineMap.getElementCount())) { ((index+1) < lineMap.getElementCount())) {
rmCount += 1;
Element e = lineMap.getElement(index+1); Element e = lineMap.getElement(index+1);
removed.addElement(e); removed.addElement(e);
rmOffs1 = e.getEndOffset(); rmOffs1 = e.getEndOffset();
......
...@@ -199,7 +199,7 @@ public class TabSet implements Serializable ...@@ -199,7 +199,7 @@ public class TabSet implements Serializable
*/ */
public String toString() { public String toString() {
int tabCount = getTabCount(); int tabCount = getTabCount();
StringBuffer buffer = new StringBuffer("[ "); StringBuilder buffer = new StringBuilder("[ ");
for(int counter = 0; counter < tabCount; counter++) { for(int counter = 0; counter < tabCount; counter++) {
if(counter > 0) if(counter > 0)
......
...@@ -362,7 +362,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -362,7 +362,7 @@ public class FormView extends ComponentView implements ActionListener {
*/ */
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
Element element = getElement(); Element element = getElement();
StringBuffer dataBuffer = new StringBuffer(); StringBuilder dataBuffer = new StringBuilder();
HTMLDocument doc = (HTMLDocument)getDocument(); HTMLDocument doc = (HTMLDocument)getDocument();
AttributeSet attr = element.getAttributes(); AttributeSet attr = element.getAttributes();
...@@ -508,7 +508,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -508,7 +508,7 @@ public class FormView extends ComponentView implements ActionListener {
*/ */
protected void imageSubmit(String imageData) { protected void imageSubmit(String imageData) {
StringBuffer dataBuffer = new StringBuffer(); StringBuilder dataBuffer = new StringBuilder();
Element elem = getElement(); Element elem = getElement();
HTMLDocument hdoc = (HTMLDocument)elem.getDocument(); HTMLDocument hdoc = (HTMLDocument)elem.getDocument();
getFormData(dataBuffer); getFormData(dataBuffer);
...@@ -589,7 +589,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -589,7 +589,7 @@ public class FormView extends ComponentView implements ActionListener {
* @param targetElement the element that triggered the * @param targetElement the element that triggered the
* form submission * form submission
*/ */
void getFormData(StringBuffer buffer) { private void getFormData(StringBuilder buffer) {
Element formE = getFormElement(); Element formE = getFormElement();
if (formE != null) { if (formE != null) {
ElementIterator it = new ElementIterator(formE); ElementIterator it = new ElementIterator(formE);
...@@ -623,7 +623,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -623,7 +623,7 @@ public class FormView extends ComponentView implements ActionListener {
* data is loaded in name/value pairs. * data is loaded in name/value pairs.
* *
*/ */
private void loadElementDataIntoBuffer(Element elem, StringBuffer buffer) { private void loadElementDataIntoBuffer(Element elem, StringBuilder buffer) {
AttributeSet attr = elem.getAttributes(); AttributeSet attr = elem.getAttributes();
String name = (String)attr.getAttribute(HTML.Attribute.NAME); String name = (String)attr.getAttribute(HTML.Attribute.NAME);
...@@ -692,29 +692,6 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -692,29 +692,6 @@ public class FormView extends ComponentView implements ActionListener {
} }
if (path != null && path.length() > 0) { if (path != null && path.length() > 0) {
value = path; value = path;
/*
try {
Reader reader = new BufferedReader(new FileReader(path));
StringBuffer buffer = new StringBuffer();
char[] cBuff = new char[1024];
int read;
try {
while ((read = reader.read(cBuff)) != -1) {
buffer.append(cBuff, 0, read);
}
} catch (IOException ioe) {
buffer = null;
}
try {
reader.close();
} catch (IOException ioe) {}
if (buffer != null) {
value = buffer.toString();
}
} catch (IOException ioe) {}
*/
} }
} }
return value; return value;
...@@ -740,7 +717,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -740,7 +717,7 @@ public class FormView extends ComponentView implements ActionListener {
* form element. Basically, only items that are selected * form element. Basically, only items that are selected
* and have their name attribute set are added to the buffer. * and have their name attribute set are added to the buffer.
*/ */
private void loadSelectData(AttributeSet attr, StringBuffer buffer) { private void loadSelectData(AttributeSet attr, StringBuilder buffer) {
String name = (String)attr.getAttribute(HTML.Attribute.NAME); String name = (String)attr.getAttribute(HTML.Attribute.NAME);
if (name == null) { if (name == null) {
...@@ -771,7 +748,7 @@ public class FormView extends ComponentView implements ActionListener { ...@@ -771,7 +748,7 @@ public class FormView extends ComponentView implements ActionListener {
* URLEncoder.encode() method before being added to the * URLEncoder.encode() method before being added to the
* buffer. * buffer.
*/ */
private void appendBuffer(StringBuffer buffer, String name, String value) { private void appendBuffer(StringBuilder buffer, String name, String value) {
if (buffer.length() > 0) { if (buffer.length() > 0) {
buffer.append('&'); buffer.append('&');
} }
......
...@@ -691,11 +691,11 @@ public class MinimalHTMLWriter extends AbstractWriter { ...@@ -691,11 +691,11 @@ public class MinimalHTMLWriter extends AbstractWriter {
if (styleNameMapping == null) { if (styleNameMapping == null) {
return style; return style;
} }
StringBuffer sb = null; StringBuilder sb = null;
for (int counter = style.length() - 1; counter >= 0; counter--) { for (int counter = style.length() - 1; counter >= 0; counter--) {
if (!isValidCharacter(style.charAt(counter))) { if (!isValidCharacter(style.charAt(counter))) {
if (sb == null) { if (sb == null) {
sb = new StringBuffer(style); sb = new StringBuilder(style);
} }
sb.setCharAt(counter, 'a'); sb.setCharAt(counter, 'a');
} }
......
...@@ -998,7 +998,7 @@ public class StyleSheet extends StyleContext { ...@@ -998,7 +998,7 @@ public class StyleSheet extends StyleContext {
void addRule(String[] selector, AttributeSet declaration, void addRule(String[] selector, AttributeSet declaration,
boolean isLinked) { boolean isLinked) {
int n = selector.length; int n = selector.length;
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append(selector[0]); sb.append(selector[0]);
for (int counter = 1; counter < n; counter++) { for (int counter = 1; counter < n; counter++) {
sb.append(' '); sb.append(' ');
......
...@@ -1470,7 +1470,7 @@ class Parser implements DTDConstants { ...@@ -1470,7 +1470,7 @@ class Parser implements DTDConstants {
*/ */
public String parseDTDMarkup() throws IOException { public String parseDTDMarkup() throws IOException {
StringBuffer strBuff = new StringBuffer(); StringBuilder strBuff = new StringBuilder();
ch = readCh(); ch = readCh();
while(true) { while(true) {
switch (ch) { switch (ch) {
......
...@@ -160,7 +160,7 @@ abstract class AbstractFilter extends OutputStream ...@@ -160,7 +160,7 @@ abstract class AbstractFilter extends OutputStream
public void write(byte[] buf, int off, int len) public void write(byte[] buf, int off, int len)
throws IOException throws IOException
{ {
StringBuffer accumulator = null; StringBuilder accumulator = null;
while (len > 0) { while (len > 0) {
short b = (short)buf[off]; short b = (short)buf[off];
...@@ -178,7 +178,7 @@ abstract class AbstractFilter extends OutputStream ...@@ -178,7 +178,7 @@ abstract class AbstractFilter extends OutputStream
char ch = translationTable[b]; char ch = translationTable[b];
if (ch != (char)0) { if (ch != (char)0) {
if (accumulator == null) if (accumulator == null)
accumulator = new StringBuffer(); accumulator = new StringBuilder();
accumulator.append(ch); accumulator.append(ch);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册