Class RhinoStringPool


  • public final class RhinoStringPool
    extends java.lang.Object
    An interning pool for strings used by the Rhino package.

    As of 2021-03-16, this custom pool is measurably more performant than `String::intern`. Some reasons for this are presented at https://shipilev.net/jvm/anatomy-quarks/10-string-intern/.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean uncheckedEquals​(java.lang.String a, java.lang.String b)
      Check if two strings are the same according to interning.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • uncheckedEquals

        public static boolean uncheckedEquals​(java.lang.String a,
                                              java.lang.String b)
        Check if two strings are the same according to interning.

        The caller is responsible for ensuring that strings passed to this method are actually interned. This method mainly exists to highlight where equality checks depend on interning for correctness.

        Ideally we could use something like a branded-type, for interned strings, to verify correct usage. However, Java doesn't support type-brands, and using like wrapper objects would undermine performance. This also needs to be ergonomic enough that callers don't resort to using `==` directly.