Skip to content

Commit

Permalink
Remove String creation in Formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrako committed Feb 27, 2024
1 parent 8b1b6c5 commit d41d122
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion jdk/src/share/classes/java/util/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4383,7 +4383,7 @@ private char getZero(Locale l) {
if (width > len && f.contains(Flags.ZERO_PAD)) {
char[] zeros = new char[width - len];
Arrays.fill(zeros, zero);
sb.insert(begin, new String(zeros));
sb.insert(begin, zeros);
}

return sb;
Expand Down
10 changes: 5 additions & 5 deletions jdk/test/java/util/Formatter/Padding.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
public class Padding {

private static class Argument {
String expected;
String format;
Object value;
final String expected;
final String format;
final Object value;

Argument(String expected, String format, Object value) {
this.expected = expected;
Expand Down Expand Up @@ -306,8 +306,8 @@ private static class Argument {
};

public static void main(String [] args) {
for(Argument arg : arguments) {
if(!arg.expected.equals(String.format(arg.format, arg.value))) {
for (Argument arg : arguments) {
if (!arg.expected.equals(String.format(arg.format, arg.value))) {
throw new RuntimeException("Expected value " + arg.expected +
" not returned from String.format(" + arg.format + ", " + arg.value + ")");
}
Expand Down

0 comments on commit d41d122

Please sign in to comment.