Use a non-exported class method for safe, reliable String hashing

Previously, we had used rewrite rules, which was unreliable: they
would only fire if a client library was compiled with optimisation,
an unsafe assumption to make.