Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan authored and rickie committed Feb 11, 2024
1 parent 57fa6ae commit 1c75f45
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ String after(Object object) {
}
}

/**
* Prefer direct invocation of {@link String#copyValueOf(char[])} over the indirection introduced
* by {@link String#copyValueOf(char[])}.
*/
static final class StringCopyValueOf {
@BeforeTemplate
String before(char[] data, int offset, int count) {
return String.copyValueOf(data, offset, count);
}

@AfterTemplate
String after(char[] data, int offset, int count) {
return new String(data, offset, count);
}
}

/**
* Prefer direct delegation to {@link String#valueOf(Object)} over the indirection introduced by
* {@link Objects#toString(Object)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@ String testSubstringRemainder() {
int testUtf8EncodedLength() {
return "foo".getBytes(UTF_8).length;
}

String testStringCopyValueOf() {
return String.copyValueOf(new char[] {'f', 'o', 'o'}, 0, 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ String testSubstringRemainder() {
int testUtf8EncodedLength() {
return Utf8.encodedLength("foo");
}

String testStringCopyValueOf() {
return new String(new char[] {'f', 'o', 'o'}, 0, 3);
}
}

0 comments on commit 1c75f45

Please sign in to comment.