Class ICUResourceBundleReader.ResourceCache

  • Enclosing class:
    ICUResourceBundleReader

    private static final class ICUResourceBundleReader.ResourceCache
    extends java.lang.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.

    • Constructor Detail

      • ResourceCache

        ResourceCache​(int maxOffset)
    • Method Detail

      • storeDirectly

        private static boolean storeDirectly​(int size)
      • putIfCleared

        private static final java.lang.Object putIfCleared​(java.lang.Object[] values,
                                                           int index,
                                                           java.lang.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

        java.lang.Object get​(int res)
      • putIfAbsent

        java.lang.Object putIfAbsent​(int res,
                                     java.lang.Object item,
                                     int size)