8274879: Replace uses of StringBuffer with StringBuilder within java.base classes

Reviewed-by: naoto
This commit is contained in:
Andrey Turbanov 2021-10-27 16:18:12 +00:00 committed by Naoto Sato
parent e6fa5fa37e
commit 9a3e954299
11 changed files with 31 additions and 31 deletions

View file

@ -78,7 +78,7 @@ public class AttributedString {
}
else {
// Build the String contents
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
for (int counter = 0; counter < iterators.length; counter++) {
appendContents(buffer, iterators[counter]);
}
@ -668,9 +668,9 @@ public class AttributedString {
/**
* Appends the contents of the CharacterIterator iterator into the
* StringBuffer buf.
* StringBuilder buf.
*/
private final void appendContents(StringBuffer buf,
private final void appendContents(StringBuilder buf,
CharacterIterator iterator) {
int index = iterator.getBeginIndex();
int end = iterator.getEndIndex();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, 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
@ -178,9 +178,9 @@ public class ChoiceFormat extends NumberFormat {
* is {@code null}
*/
public void applyPattern(String newPattern) {
StringBuffer[] segments = new StringBuffer[2];
StringBuilder[] segments = new StringBuilder[2];
for (int i = 0; i < segments.length; ++i) {
segments[i] = new StringBuffer();
segments[i] = new StringBuilder();
}
double[] newChoiceLimits = new double[30];
String[] newChoiceFormats = new String[30];

View file

@ -1264,8 +1264,8 @@ public final class CompactNumberFormat extends NumberFormat {
String zeros = "";
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
StringBuffer prefix = new StringBuffer();
StringBuffer suffix = new StringBuffer();
StringBuilder prefix = new StringBuilder();
StringBuilder suffix = new StringBuilder();
boolean inQuote = false;
// The phase ranges from 0 to 2. Phase 0 is the prefix. Phase 1 is
// the section of the pattern with digits. Phase 2 is the suffix.
@ -1275,7 +1275,7 @@ public final class CompactNumberFormat extends NumberFormat {
int phase = 0;
// The affix is either the prefix or the suffix.
StringBuffer affix = prefix;
StringBuilder affix = prefix;
for (int pos = start; pos < pattern.length(); ++pos) {
char ch = pattern.charAt(pos);

View file

@ -2961,8 +2961,8 @@ public class DecimalFormat extends NumberFormat {
* the expanded affix strings up to date.
*/
private void expandAffixes() {
// Reuse one StringBuffer for better performance
StringBuffer buffer = new StringBuffer();
// Reuse one StringBuilder for better performance
StringBuilder buffer = new StringBuilder();
if (posPrefixPattern != null) {
positivePrefix = expandAffix(posPrefixPattern, buffer);
positivePrefixFieldPositions = null;
@ -2992,10 +2992,10 @@ public class DecimalFormat extends NumberFormat {
* itself at the end of the pattern.
*
* @param pattern the non-null, possibly empty pattern
* @param buffer a scratch StringBuffer; its contents will be lost
* @param buffer a scratch StringBuilder; its contents will be lost
* @return the expanded equivalent of pattern
*/
private String expandAffix(String pattern, StringBuffer buffer) {
private String expandAffix(String pattern, StringBuilder buffer) {
buffer.setLength(0);
for (int i=0; i<pattern.length(); ) {
char c = pattern.charAt(i++);
@ -3097,7 +3097,7 @@ public class DecimalFormat extends NumberFormat {
}
/**
* Appends an affix pattern to the given StringBuffer, quoting special
* Appends an affix pattern to the given StringBuilder, quoting special
* characters as needed. Uses the internal affix pattern, if that exists,
* or the literal affix, if the internal affix pattern is null. The
* appended string will generate the same affix pattern (or literal affix)
@ -3111,7 +3111,7 @@ public class DecimalFormat extends NumberFormat {
* @param localized true if the appended pattern should contain localized
* pattern characters; otherwise, non-localized pattern chars are appended
*/
private void appendAffix(StringBuffer buffer, String affixPattern,
private void appendAffix(StringBuilder buffer, String affixPattern,
String expAffix, boolean localized) {
if (affixPattern == null) {
appendAffix(buffer, expAffix, localized);
@ -3156,11 +3156,11 @@ public class DecimalFormat extends NumberFormat {
}
/**
* Append an affix to the given StringBuffer, using quotes if
* Append an affix to the given StringBuilder, using quotes if
* there are special characters. Single quotes themselves must be
* escaped in either case.
*/
private void appendAffix(StringBuffer buffer, String affix, boolean localized) {
private void appendAffix(StringBuilder buffer, String affix, boolean localized) {
boolean needQuote;
if (localized) {
needQuote = affix.indexOf(symbols.getZeroDigit()) >= 0
@ -3198,7 +3198,7 @@ public class DecimalFormat extends NumberFormat {
/**
* Does the real work of generating a pattern. */
private String toPattern(boolean localized) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
for (int j = 1; j >= 0; --j) {
if (j == 1)
appendAffix(result, posPrefixPattern, positivePrefix, localized);
@ -3341,8 +3341,8 @@ public class DecimalFormat extends NumberFormat {
int start = 0;
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
boolean inQuote = false;
StringBuffer prefix = new StringBuffer();
StringBuffer suffix = new StringBuffer();
StringBuilder prefix = new StringBuilder();
StringBuilder suffix = new StringBuilder();
int decimalPos = -1;
int multiplier = 1;
int digitLeftCount = 0, zeroDigitCount = 0, digitRightCount = 0;
@ -3358,7 +3358,7 @@ public class DecimalFormat extends NumberFormat {
int phase = 0;
// The affix is either the prefix or the suffix.
StringBuffer affix = prefix;
StringBuilder affix = prefix;
for (int pos = start; pos < pattern.length(); ++pos) {
char ch = pattern.charAt(pos);

View file

@ -401,7 +401,7 @@ final class RBTableBuilder {
// can work right
if (fwd && groupChars.length() > 1) {
addContractFlags(groupChars);
addContractOrder(new StringBuffer(groupChars).reverse().toString(),
addContractOrder(new StringBuilder(groupChars).reverse().toString(),
anOrder, false);
}
}