Class ICUResourceBundleReader.ResourceCache

java.lang.Object
com.ibm.icu.impl.ICUResourceBundleReader.ResourceCache
Enclosing class:
ICUResourceBundleReader

private static final class ICUResourceBundleReader.ResourceCache extends Object
Cache of some of one resource bundle's resources. Avoids creating multiple Java objects for the same resource items, including multiple copies of their contents.

Mutable objects must not be cached and then returned to the caller because the cache must not be writable via the returned reference.

Resources are mapped by their resource integers. Empty resources with offset 0 cannot be mapped. Integers need not and should not be cached. Multiple .res items may share resource offsets (genrb eliminates some duplicates).

This cache uses int[] and Object[] arrays to minimize object creation and avoid auto-boxing.

Large resource objects are usually stored in SoftReferences.

For few resources, a small table is used with binary search. When more resources are cached, then the data structure changes to be faster but also use more memory.

  • Field Details

  • Constructor Details

    • ResourceCache

      ResourceCache(int maxOffset)
  • Method Details

    • storeDirectly

      private static boolean storeDirectly(int size)
    • putIfCleared

      private static final Object putIfCleared(Object[] values, int index, Object item, int size)
    • makeKey

      private int makeKey(int res)
      Turns a resource integer (with unused bits in the middle) into a key with fewer bits (at most keyBits).
    • findSimple

      private int findSimple(int key)
    • get

      Object get(int res)
    • putIfAbsent

      Object putIfAbsent(int res, Object item, int size)