8274879: Replace uses of StringBuffer with StringBuilder within java.base classes
Reviewed-by: naoto
This commit is contained in:
parent
e6fa5fa37e
commit
9a3e954299
@ -179,7 +179,7 @@ public final class FilePermission extends Permission implements Serializable {
|
||||
private static final char WILD_CHAR = '*';
|
||||
|
||||
// public String toString() {
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.append("*** FilePermission on " + getName() + " ***");
|
||||
// for (Field f : FilePermission.class.getDeclaredFields()) {
|
||||
// if (!Modifier.isStatic(f.getModifiers())) {
|
||||
|
@ -1297,7 +1297,7 @@ public final class SocketPermission extends Permission
|
||||
/*
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer s = new StringBuffer(super.toString() + "\n" +
|
||||
StringBuilder s = new StringBuilder(super.toString() + "\n" +
|
||||
"cname = " + cname + "\n" +
|
||||
"wildcard = " + wildcard + "\n" +
|
||||
"invalid = " + invalid + "\n" +
|
||||
|
@ -1762,7 +1762,7 @@ final class UrlDeserializedState {
|
||||
|
||||
String reconstituteUrlString() {
|
||||
|
||||
// pre-compute length of StringBuffer
|
||||
// pre-compute length of StringBuilder
|
||||
int len = protocol.length() + 1;
|
||||
if (authority != null && !authority.isEmpty())
|
||||
len += 2 + authority.length();
|
||||
|
@ -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();
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 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
|
||||
@ -262,7 +262,7 @@ public class Debug {
|
||||
private static String marshal(String args) {
|
||||
if (args != null) {
|
||||
StringBuilder target = new StringBuilder();
|
||||
StringBuffer source = new StringBuffer(args);
|
||||
StringBuilder source = new StringBuilder(args);
|
||||
|
||||
// obtain the "permission=<classname>" options
|
||||
// the syntax of classname: IDENTIFIER.IDENTIFIER
|
||||
@ -274,7 +274,7 @@ public class Debug {
|
||||
"[a-zA-Z_$][a-zA-Z0-9_$]*([.][a-zA-Z_$][a-zA-Z0-9_$]*)*";
|
||||
Pattern pattern = Pattern.compile(reg);
|
||||
Matcher matcher = pattern.matcher(source);
|
||||
StringBuffer left = new StringBuffer();
|
||||
StringBuilder left = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
String matched = matcher.group();
|
||||
target.append(matched.replaceFirst(keyReg, keyStr));
|
||||
@ -298,7 +298,7 @@ public class Debug {
|
||||
reg = keyReg + "[^, ;]*";
|
||||
pattern = Pattern.compile(reg);
|
||||
matcher = pattern.matcher(source);
|
||||
left = new StringBuffer();
|
||||
left = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
String matched = matcher.group();
|
||||
target.append(matched.replaceFirst(keyReg, keyStr));
|
||||
|
@ -94,7 +94,7 @@ public class JulianCalendar extends BaseCalendar {
|
||||
public String toString() {
|
||||
String time = super.toString();
|
||||
time = time.substring(time.indexOf('T'));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Era era = getEra();
|
||||
if (era != null) {
|
||||
String n = era.getAbbreviation();
|
||||
|
@ -123,7 +123,7 @@ public class LocalGregorianCalendar extends BaseCalendar {
|
||||
public String toString() {
|
||||
String time = super.toString();
|
||||
time = time.substring(time.indexOf('T'));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Era era = getEra();
|
||||
if (era != null) {
|
||||
String abbr = era.getAbbreviation();
|
||||
|
Loading…
x
Reference in New Issue
Block a user