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 = '*';
|
private static final char WILD_CHAR = '*';
|
||||||
|
|
||||||
// public String toString() {
|
// public String toString() {
|
||||||
// StringBuffer sb = new StringBuffer();
|
// StringBuilder sb = new StringBuilder();
|
||||||
// sb.append("*** FilePermission on " + getName() + " ***");
|
// sb.append("*** FilePermission on " + getName() + " ***");
|
||||||
// for (Field f : FilePermission.class.getDeclaredFields()) {
|
// for (Field f : FilePermission.class.getDeclaredFields()) {
|
||||||
// if (!Modifier.isStatic(f.getModifiers())) {
|
// if (!Modifier.isStatic(f.getModifiers())) {
|
||||||
|
@ -1297,7 +1297,7 @@ public final class SocketPermission extends Permission
|
|||||||
/*
|
/*
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
StringBuffer s = new StringBuffer(super.toString() + "\n" +
|
StringBuilder s = new StringBuilder(super.toString() + "\n" +
|
||||||
"cname = " + cname + "\n" +
|
"cname = " + cname + "\n" +
|
||||||
"wildcard = " + wildcard + "\n" +
|
"wildcard = " + wildcard + "\n" +
|
||||||
"invalid = " + invalid + "\n" +
|
"invalid = " + invalid + "\n" +
|
||||||
|
@ -1762,7 +1762,7 @@ final class UrlDeserializedState {
|
|||||||
|
|
||||||
String reconstituteUrlString() {
|
String reconstituteUrlString() {
|
||||||
|
|
||||||
// pre-compute length of StringBuffer
|
// pre-compute length of StringBuilder
|
||||||
int len = protocol.length() + 1;
|
int len = protocol.length() + 1;
|
||||||
if (authority != null && !authority.isEmpty())
|
if (authority != null && !authority.isEmpty())
|
||||||
len += 2 + authority.length();
|
len += 2 + authority.length();
|
||||||
|
@ -78,7 +78,7 @@ public class AttributedString {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Build the String contents
|
// Build the String contents
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuilder buffer = new StringBuilder();
|
||||||
for (int counter = 0; counter < iterators.length; counter++) {
|
for (int counter = 0; counter < iterators.length; counter++) {
|
||||||
appendContents(buffer, iterators[counter]);
|
appendContents(buffer, iterators[counter]);
|
||||||
}
|
}
|
||||||
@ -668,9 +668,9 @@ public class AttributedString {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends the contents of the CharacterIterator iterator into the
|
* 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) {
|
CharacterIterator iterator) {
|
||||||
int index = iterator.getBeginIndex();
|
int index = iterator.getBeginIndex();
|
||||||
int end = iterator.getEndIndex();
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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}
|
* is {@code null}
|
||||||
*/
|
*/
|
||||||
public void applyPattern(String newPattern) {
|
public void applyPattern(String newPattern) {
|
||||||
StringBuffer[] segments = new StringBuffer[2];
|
StringBuilder[] segments = new StringBuilder[2];
|
||||||
for (int i = 0; i < segments.length; ++i) {
|
for (int i = 0; i < segments.length; ++i) {
|
||||||
segments[i] = new StringBuffer();
|
segments[i] = new StringBuilder();
|
||||||
}
|
}
|
||||||
double[] newChoiceLimits = new double[30];
|
double[] newChoiceLimits = new double[30];
|
||||||
String[] newChoiceFormats = new String[30];
|
String[] newChoiceFormats = new String[30];
|
||||||
|
@ -1264,8 +1264,8 @@ public final class CompactNumberFormat extends NumberFormat {
|
|||||||
String zeros = "";
|
String zeros = "";
|
||||||
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
|
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
|
||||||
|
|
||||||
StringBuffer prefix = new StringBuffer();
|
StringBuilder prefix = new StringBuilder();
|
||||||
StringBuffer suffix = new StringBuffer();
|
StringBuilder suffix = new StringBuilder();
|
||||||
boolean inQuote = false;
|
boolean inQuote = false;
|
||||||
// The phase ranges from 0 to 2. Phase 0 is the prefix. Phase 1 is
|
// 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.
|
// 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;
|
int phase = 0;
|
||||||
|
|
||||||
// The affix is either the prefix or the suffix.
|
// The affix is either the prefix or the suffix.
|
||||||
StringBuffer affix = prefix;
|
StringBuilder affix = prefix;
|
||||||
|
|
||||||
for (int pos = start; pos < pattern.length(); ++pos) {
|
for (int pos = start; pos < pattern.length(); ++pos) {
|
||||||
char ch = pattern.charAt(pos);
|
char ch = pattern.charAt(pos);
|
||||||
|
@ -2961,8 +2961,8 @@ public class DecimalFormat extends NumberFormat {
|
|||||||
* the expanded affix strings up to date.
|
* the expanded affix strings up to date.
|
||||||
*/
|
*/
|
||||||
private void expandAffixes() {
|
private void expandAffixes() {
|
||||||
// Reuse one StringBuffer for better performance
|
// Reuse one StringBuilder for better performance
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuilder buffer = new StringBuilder();
|
||||||
if (posPrefixPattern != null) {
|
if (posPrefixPattern != null) {
|
||||||
positivePrefix = expandAffix(posPrefixPattern, buffer);
|
positivePrefix = expandAffix(posPrefixPattern, buffer);
|
||||||
positivePrefixFieldPositions = null;
|
positivePrefixFieldPositions = null;
|
||||||
@ -2992,10 +2992,10 @@ public class DecimalFormat extends NumberFormat {
|
|||||||
* itself at the end of the pattern.
|
* itself at the end of the pattern.
|
||||||
*
|
*
|
||||||
* @param pattern the non-null, possibly empty 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
|
* @return the expanded equivalent of pattern
|
||||||
*/
|
*/
|
||||||
private String expandAffix(String pattern, StringBuffer buffer) {
|
private String expandAffix(String pattern, StringBuilder buffer) {
|
||||||
buffer.setLength(0);
|
buffer.setLength(0);
|
||||||
for (int i=0; i<pattern.length(); ) {
|
for (int i=0; i<pattern.length(); ) {
|
||||||
char c = pattern.charAt(i++);
|
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,
|
* characters as needed. Uses the internal affix pattern, if that exists,
|
||||||
* or the literal affix, if the internal affix pattern is null. The
|
* or the literal affix, if the internal affix pattern is null. The
|
||||||
* appended string will generate the same affix pattern (or literal affix)
|
* 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
|
* @param localized true if the appended pattern should contain localized
|
||||||
* pattern characters; otherwise, non-localized pattern chars are appended
|
* 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) {
|
String expAffix, boolean localized) {
|
||||||
if (affixPattern == null) {
|
if (affixPattern == null) {
|
||||||
appendAffix(buffer, expAffix, localized);
|
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
|
* there are special characters. Single quotes themselves must be
|
||||||
* escaped in either case.
|
* escaped in either case.
|
||||||
*/
|
*/
|
||||||
private void appendAffix(StringBuffer buffer, String affix, boolean localized) {
|
private void appendAffix(StringBuilder buffer, String affix, boolean localized) {
|
||||||
boolean needQuote;
|
boolean needQuote;
|
||||||
if (localized) {
|
if (localized) {
|
||||||
needQuote = affix.indexOf(symbols.getZeroDigit()) >= 0
|
needQuote = affix.indexOf(symbols.getZeroDigit()) >= 0
|
||||||
@ -3198,7 +3198,7 @@ public class DecimalFormat extends NumberFormat {
|
|||||||
/**
|
/**
|
||||||
* Does the real work of generating a pattern. */
|
* Does the real work of generating a pattern. */
|
||||||
private String toPattern(boolean localized) {
|
private String toPattern(boolean localized) {
|
||||||
StringBuffer result = new StringBuffer();
|
StringBuilder result = new StringBuilder();
|
||||||
for (int j = 1; j >= 0; --j) {
|
for (int j = 1; j >= 0; --j) {
|
||||||
if (j == 1)
|
if (j == 1)
|
||||||
appendAffix(result, posPrefixPattern, positivePrefix, localized);
|
appendAffix(result, posPrefixPattern, positivePrefix, localized);
|
||||||
@ -3341,8 +3341,8 @@ public class DecimalFormat extends NumberFormat {
|
|||||||
int start = 0;
|
int start = 0;
|
||||||
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
|
for (int j = 1; j >= 0 && start < pattern.length(); --j) {
|
||||||
boolean inQuote = false;
|
boolean inQuote = false;
|
||||||
StringBuffer prefix = new StringBuffer();
|
StringBuilder prefix = new StringBuilder();
|
||||||
StringBuffer suffix = new StringBuffer();
|
StringBuilder suffix = new StringBuilder();
|
||||||
int decimalPos = -1;
|
int decimalPos = -1;
|
||||||
int multiplier = 1;
|
int multiplier = 1;
|
||||||
int digitLeftCount = 0, zeroDigitCount = 0, digitRightCount = 0;
|
int digitLeftCount = 0, zeroDigitCount = 0, digitRightCount = 0;
|
||||||
@ -3358,7 +3358,7 @@ public class DecimalFormat extends NumberFormat {
|
|||||||
int phase = 0;
|
int phase = 0;
|
||||||
|
|
||||||
// The affix is either the prefix or the suffix.
|
// The affix is either the prefix or the suffix.
|
||||||
StringBuffer affix = prefix;
|
StringBuilder affix = prefix;
|
||||||
|
|
||||||
for (int pos = start; pos < pattern.length(); ++pos) {
|
for (int pos = start; pos < pattern.length(); ++pos) {
|
||||||
char ch = pattern.charAt(pos);
|
char ch = pattern.charAt(pos);
|
||||||
|
@ -401,7 +401,7 @@ final class RBTableBuilder {
|
|||||||
// can work right
|
// can work right
|
||||||
if (fwd && groupChars.length() > 1) {
|
if (fwd && groupChars.length() > 1) {
|
||||||
addContractFlags(groupChars);
|
addContractFlags(groupChars);
|
||||||
addContractOrder(new StringBuffer(groupChars).reverse().toString(),
|
addContractOrder(new StringBuilder(groupChars).reverse().toString(),
|
||||||
anOrder, false);
|
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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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) {
|
private static String marshal(String args) {
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
StringBuilder target = new StringBuilder();
|
StringBuilder target = new StringBuilder();
|
||||||
StringBuffer source = new StringBuffer(args);
|
StringBuilder source = new StringBuilder(args);
|
||||||
|
|
||||||
// obtain the "permission=<classname>" options
|
// obtain the "permission=<classname>" options
|
||||||
// the syntax of classname: IDENTIFIER.IDENTIFIER
|
// 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_$]*)*";
|
"[a-zA-Z_$][a-zA-Z0-9_$]*([.][a-zA-Z_$][a-zA-Z0-9_$]*)*";
|
||||||
Pattern pattern = Pattern.compile(reg);
|
Pattern pattern = Pattern.compile(reg);
|
||||||
Matcher matcher = pattern.matcher(source);
|
Matcher matcher = pattern.matcher(source);
|
||||||
StringBuffer left = new StringBuffer();
|
StringBuilder left = new StringBuilder();
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String matched = matcher.group();
|
String matched = matcher.group();
|
||||||
target.append(matched.replaceFirst(keyReg, keyStr));
|
target.append(matched.replaceFirst(keyReg, keyStr));
|
||||||
@ -298,7 +298,7 @@ public class Debug {
|
|||||||
reg = keyReg + "[^, ;]*";
|
reg = keyReg + "[^, ;]*";
|
||||||
pattern = Pattern.compile(reg);
|
pattern = Pattern.compile(reg);
|
||||||
matcher = pattern.matcher(source);
|
matcher = pattern.matcher(source);
|
||||||
left = new StringBuffer();
|
left = new StringBuilder();
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String matched = matcher.group();
|
String matched = matcher.group();
|
||||||
target.append(matched.replaceFirst(keyReg, keyStr));
|
target.append(matched.replaceFirst(keyReg, keyStr));
|
||||||
|
@ -94,7 +94,7 @@ public class JulianCalendar extends BaseCalendar {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
String time = super.toString();
|
String time = super.toString();
|
||||||
time = time.substring(time.indexOf('T'));
|
time = time.substring(time.indexOf('T'));
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
Era era = getEra();
|
Era era = getEra();
|
||||||
if (era != null) {
|
if (era != null) {
|
||||||
String n = era.getAbbreviation();
|
String n = era.getAbbreviation();
|
||||||
|
@ -123,7 +123,7 @@ public class LocalGregorianCalendar extends BaseCalendar {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
String time = super.toString();
|
String time = super.toString();
|
||||||
time = time.substring(time.indexOf('T'));
|
time = time.substring(time.indexOf('T'));
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
Era era = getEra();
|
Era era = getEra();
|
||||||
if (era != null) {
|
if (era != null) {
|
||||||
String abbr = era.getAbbreviation();
|
String abbr = era.getAbbreviation();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user