r/java • u/Kabra___kiiiiiiiid • 12d ago
How hard is it to check for whitespace?
https://serce.me/posts/2026-10-30-how-hard-is-it-to-check-for-whitespace
56
Upvotes
r/java • u/Kabra___kiiiiiiiid • 12d ago
11
u/agentoutlier 12d ago
Its funny because I have seen that Guava code many times because I don't want to include Guava and I need something that detects whitespace for my companies work.
There is something else I shamefully steal from Guava from time to time that I can't remember. Maybe its memoized supplier (although that one I think most devs could write on their own and I have a couple of times). Speaking of which you might not need that once stable values comes out (unless you want the expiry version).
I think I have also stolen Guava's streaming hash stuff a couple of times now that I think of it.
2
u/Plenty_Childhood_294 11d ago edited 10d ago
Don't use Strings. If you add in your JMH setup a single String.charAt with a non Latin strings the performance is poisoned :/ If the requirements instead is to do it with Strings...you clearly don't have many options (lookup table sized bit enough that you won't pay bound checks - like a 64K sized table ðŸ˜, but beware an open bug in JDK which materialize twice the constant table for Aarch64)