Package kala.compress.harmony.unpack200
Class SegmentConstantPoolArrayCache
- java.lang.Object
-
- kala.compress.harmony.unpack200.SegmentConstantPoolArrayCache
-
public class SegmentConstantPoolArrayCache extends java.lang.ObjectThe SegmentConstantPool spends a lot of time searching through large arrays of Strings looking for matches. This can be sped up by caching the arrays in HashMaps so the String keys are looked up and resolve to positions in the array rather than iterating through the arrays each time. Because the arrays only grow (never shrink or change) we can use the last known size as a way to determine if the array has changed. Note that this cache must be synchronized externally if it is shared.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classSegmentConstantPoolArrayCache.CachedArrayKeeps track of the last known size of an array as well as a HashMap that knows the mapping from element values to the indices of the array which contain that value.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.IdentityHashMap<java.lang.String[],SegmentConstantPoolArrayCache.CachedArray>knownArraysprotected java.lang.String[]lastArrayprotected java.util.List<java.lang.Integer>lastIndexesprotected java.lang.StringlastKey
-
Constructor Summary
Constructors Constructor Description SegmentConstantPoolArrayCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanarrayIsCached(java.lang.String[] array)Tests whether a String array is correctly cached.protected voidcacheArray(java.lang.String[] array)Caches the array passed in as the argumentjava.util.List<java.lang.Integer>indexesForArrayKey(java.lang.String[] array, java.lang.String key)Gets the indices for the given key in the given array.
-
-
-
Field Detail
-
knownArrays
protected java.util.IdentityHashMap<java.lang.String[],SegmentConstantPoolArrayCache.CachedArray> knownArrays
-
lastIndexes
protected java.util.List<java.lang.Integer> lastIndexes
-
lastArray
protected java.lang.String[] lastArray
-
lastKey
protected java.lang.String lastKey
-
-
Method Detail
-
arrayIsCached
protected boolean arrayIsCached(java.lang.String[] array)
Tests whether a String array is correctly cached. Return false if the array is not cached, or if the array cache is outdated.- Parameters:
array- of String- Returns:
- boolean true if up-to-date cache, otherwise false.
-
cacheArray
protected void cacheArray(java.lang.String[] array)
Caches the array passed in as the argument- Parameters:
array- String[] to cache
-
indexesForArrayKey
public java.util.List<java.lang.Integer> indexesForArrayKey(java.lang.String[] array, java.lang.String key)Gets the indices for the given key in the given array. If no such key exists in the cached array, answer -1.- Parameters:
array- String[] array to search for the valuekey- String value for which to search- Returns:
- List collection of index positions in the array
-
-