RFR: 8302863: Speed up String::encodeASCII using countPositives
Claes Redestad
redestad at openjdk.org
Mon Feb 20 11:55:10 UTC 2023
When encoding Strings to US-ASCII we can speed up the happy path significantly by using `StringCoding.countPositives` as a speculative check for whether there are any chars that needs to be replaced by `'?'`. Once a non-ASCII char is encountered we fall back to the slow loop and replace as needed.
An alternative could be unrolling or using a byte array VarHandle, as show-cased by Brett Okken here: https://mail.openjdk.org/pipermail/core-libs-dev/2023-February/100573.html Having to replace chars with `?` is essentially an encoding error so it might be safe to assume this case is exceptional in practice.
-------------
Commit messages:
- Cleanup, clone
- Merge branch 'master' into encodeASCII
- Improve encodeASCII by leveraging countPositives
Changes: https://git.openjdk.org/jdk/pull/12640/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12640&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8302863
Stats: 24 lines in 1 file changed: 11 ins; 2 del; 11 mod
Patch: https://git.openjdk.org/jdk/pull/12640.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/12640/head:pull/12640
PR: https://git.openjdk.org/jdk/pull/12640
More information about the core-libs-dev
mailing list