GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix AsciiString.cached(String) performance regression (#17074) · netty/netty@1683570

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • common/src/main/java/io/netty/util
    • AsciiString.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common/src/main/java/io/netty/util/AsciiString.java‎

Copy file name to clipboardExpand all lines: common/src/main/java/io/netty/util/AsciiString.java
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,17 +1396,18 @@ public static AsciiString of(CharSequence string) {
13961396
* where the guaranteed use of the {@link #toString()} method.
13971397
*/
13981398
public static AsciiString cached(String string) {
1399-
AsciiString asciiString = new AsciiString(string);
1400-
asciiString.string = string;
1401-
// Check if the input contains any non-Latin-1 characters that would have been
1402-
// truncated to '?' by c2b() during construction. If so, reconstruct the cached
1403-
// string from the byte array to ensure consistency.
1404-
for (int i = 0; i < string.length(); i++) {
1405-
if (string.charAt(i) > MAX_CHAR_VALUE) {
1406-
asciiString.string = asciiString.toString(0);
1407-
break;
1399+
byte[] value = PlatformDependent.allocateUninitializedArray(string.length());
1400+
boolean allLatin1 = true;
1401+
for (int i = 0; i < value.length; i++) {
1402+
char c = string.charAt(i);
1403+
value[i] = c2b(c);
1404+
if (c > MAX_CHAR_VALUE) {
1405+
allLatin1 = false;
14081406
}
14091407
}
1408+
1409+
AsciiString asciiString = new AsciiString(value, false);
1410+
asciiString.string = allLatin1 ? string : asciiString.toString(0);
14101411
return asciiString;
14111412
}
14121413

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.