mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8339290: Optimize ClassFile Utf8EntryImpl#writeTo
Reviewed-by: redestad, liach
This commit is contained in:
parent
340e131d61
commit
cb9f5c5791
7 changed files with 268 additions and 49 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024, Alibaba Group Holding Limited. 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
|
||||
|
@ -34,6 +35,45 @@ class StringCoding {
|
|||
|
||||
private StringCoding() { }
|
||||
|
||||
/**
|
||||
* Count the number of leading non-zero ascii chars in the range.
|
||||
*/
|
||||
public static int countNonZeroAscii(String s) {
|
||||
byte[] value = s.value();
|
||||
if (s.isLatin1()) {
|
||||
return countNonZeroAsciiLatin1(value, 0, value.length);
|
||||
} else {
|
||||
return countNonZeroAsciiUTF16(value, 0, s.length());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of non-zero ascii chars in the range.
|
||||
*/
|
||||
public static int countNonZeroAsciiLatin1(byte[] ba, int off, int len) {
|
||||
int limit = off + len;
|
||||
for (int i = off; i < limit; i++) {
|
||||
if (ba[i] <= 0) {
|
||||
return i - off;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of leading non-zero ascii chars in the range.
|
||||
*/
|
||||
public static int countNonZeroAsciiUTF16(byte[] ba, int off, int strlen) {
|
||||
int limit = off + strlen;
|
||||
for (int i = off; i < limit; i++) {
|
||||
char c = StringUTF16.charAt(ba, i);
|
||||
if (c == 0 || c > 0x7F) {
|
||||
return i - off;
|
||||
}
|
||||
}
|
||||
return strlen;
|
||||
}
|
||||
|
||||
public static boolean hasNegatives(byte[] ba, int off, int len) {
|
||||
return countPositives(ba, off, len) != len;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue