Class RhinoStringPool

java.lang.Object
com.google.javascript.rhino.RhinoStringPool

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

As of 2021-03-16 and again as of 2024-12-09, this custom pool is measurably more performant than `String::intern`.

  • Method Details

    • uncheckedEquals

      public static boolean uncheckedEquals(String a, 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.

    • addOrGet

      public static String addOrGet(String s)