When encoding Strings to US-ASCII we can speed things up the normal path significantly by using StringCoding.countPositives. Once a non-ASCII char is encountered we fall back to the slow loop.
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
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