RFR: 8215380: Backout accidental change to String::length
Claes Redestad
claes.redestad at oracle.com
Thu Dec 13 23:20:03 UTC 2018
Hi,
I need to revert an accidental change to String.length
Bug: https://bugs.openjdk.java.net/browse/JDK-8215380
Patch inlined below
Running the accidentally pushed version in naive microbenchmarks showed
that avoiding the shift operation can improve throughput of str.length()
by a small measure (~1.06x) for latin1-only inputs, neutral for mixed
or utf16-only inputs, but also adds a branch (visible in profiling)
which could blow up in more real cases. Regardless, it should be
reviewed and discussed on it's own merits. Sorry!
/Claes
diff -r 8bf9268df0e2 src/java.base/share/classes/java/lang/String.java
--- a/src/java.base/share/classes/java/lang/String.java Thu Dec 13
15:31:05 2018 +0100
+++ b/src/java.base/share/classes/java/lang/String.java Thu Dec 13
23:59:43 2018 +0100
@@ -664,7 +664,7 @@
* object.
*/
public int length() {
- return isLatin1() ? value.length : value.length >> UTF16;
+ return value.length >> coder();
}
/**
More information about the core-libs-dev
mailing list