Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8274879: Replace uses of StringBuffer with StringBuilder within java.…
…base classes

Reviewed-by: naoto
  • Loading branch information
turbanoff authored and naotoj committed Oct 27, 2021
1 parent e6fa5fa commit 9a3e954
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/io/FilePermission.java
Expand Up @@ -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())) {
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/net/SocketPermission.java
Expand Up @@ -1297,7 +1297,7 @@ private static boolean inRange(
/*
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" +
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/net/URL.java
Expand Up @@ -1762,7 +1762,7 @@ int getHashCode () {

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();
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/text/AttributedString.java
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -668,9 +668,9 @@ private static final boolean valuesMatch(Object value1, Object value2) {

/**
* 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();
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/text/ChoiceFormat.java
@@ -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
Expand Down Expand Up @@ -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];
Expand Down
Expand Up @@ -1264,8 +1264,8 @@ private void applyPattern(String count, String pattern, int index) {
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.
Expand All @@ -1275,7 +1275,7 @@ private void applyPattern(String count, String pattern, int index) {
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);
Expand Down
24 changes: 12 additions & 12 deletions src/java.base/share/classes/java/text/DecimalFormat.java
Expand Up @@ -2961,8 +2961,8 @@ public String toLocalizedPattern() {
* 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;
Expand Down Expand Up @@ -2992,10 +2992,10 @@ private void expandAffixes() {
* 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++);
Expand Down Expand Up @@ -3097,7 +3097,7 @@ private FieldPosition[] expandAffix(String pattern) {
}

/**
* 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)
Expand All @@ -3111,7 +3111,7 @@ private FieldPosition[] expandAffix(String pattern) {
* @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);
Expand Down Expand Up @@ -3156,11 +3156,11 @@ private void appendAffix(StringBuffer buffer, String affixPattern,
}

/**
* 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
Expand Down Expand Up @@ -3198,7 +3198,7 @@ private void appendAffix(StringBuffer buffer, String affix, boolean localized) {
/**
* 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);
Expand Down Expand Up @@ -3341,8 +3341,8 @@ private void applyPattern(String pattern, boolean localized) {
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;
Expand All @@ -3358,7 +3358,7 @@ private void applyPattern(String pattern, boolean localized) {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/text/RBTableBuilder.java
Expand Up @@ -401,7 +401,7 @@ private final void addContractOrder(String groupChars, int anOrder,
// can work right
if (fwd && groupChars.length() > 1) {
addContractFlags(groupChars);
addContractOrder(new StringBuffer(groupChars).reverse().toString(),
addContractOrder(new StringBuilder(groupChars).reverse().toString(),
anOrder, false);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/sun/security/util/Debug.java
@@ -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
Expand Down Expand Up @@ -262,7 +262,7 @@ public static String toHexString(BigInteger b) {
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
Expand All @@ -274,7 +274,7 @@ private static String marshal(String args) {
"[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));
Expand All @@ -298,7 +298,7 @@ private static String marshal(String args) {
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));
Expand Down
Expand Up @@ -94,7 +94,7 @@ public void setNormalizedYear(int year) {
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();
Expand Down
Expand Up @@ -123,7 +123,7 @@ void setLocalYear(int year) {
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();
Expand Down

1 comment on commit 9a3e954

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.