Class DslJson.SimpleStringCache

java.lang.Object
com.dslplatform.json.DslJson.SimpleStringCache
All Implemented Interfaces:
StringCache
Enclosing class:
DslJson<TContext>

public static class DslJson.SimpleStringCache extends Object implements StringCache
Simplistic string cache implementation. It uses a fixed String[] structure in which it caches string value based on it's hash. Eg, hash & mask provide index into the structure. Different string with same hash will overwrite the previous one.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String[]
     
    private final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Will use String[] with 1024 elements.
    SimpleStringCache(int log2Size)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
    createAndPut(int index, char[] chars, int len)
     
    get(char[] chars, int len)
    Calculates hash of the provided "string" and looks it up from the String[] It it doesn't exists of a different string is already there a new String instance is created and saved into the String[]

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mask

      private final int mask
    • cache

      private final String[] cache
  • Constructor Details

    • SimpleStringCache

      public SimpleStringCache()
      Will use String[] with 1024 elements.
    • SimpleStringCache

      public SimpleStringCache(int log2Size)
  • Method Details

    • get

      public String get(char[] chars, int len)
      Calculates hash of the provided "string" and looks it up from the String[] It it doesn't exists of a different string is already there a new String instance is created and saved into the String[]
      Specified by:
      get in interface StringCache
      Parameters:
      chars - buffer into which string was parsed
      len - the string length inside the buffer
      Returns:
      String instance matching the char[]/int pair
    • createAndPut

      private String createAndPut(int index, char[] chars, int len)