Code refactoring for TextLayoutCache

- rename TextLayoutCache entry name
- update references to old name
- better variable names in TextLayoutCache::getRunAdvances()

Change-Id: I5173fbc8af79437ce4786084580426f130120ce8
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 27be871..fbb9cea 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -407,7 +407,7 @@
         HB_ShaperItem shaperItem;
         HB_FontRec font;
         FontData fontData;
-        RunAdvanceDescription::shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, text,
+        TextLayoutCacheValue::shapeWithHarfbuzz(&shaperItem, &font, &fontData, paint, text,
                 start, count, contextCount, flags);
 
         int glyphCount = shaperItem.num_glyphs;
diff --git a/core/jni/android/graphics/TextLayout.cpp b/core/jni/android/graphics/TextLayout.cpp
index 434f63b..2578ea1 100644
--- a/core/jni/android/graphics/TextLayout.cpp
+++ b/core/jni/android/graphics/TextLayout.cpp
@@ -264,7 +264,7 @@
             dirFlags, resultAdvances, &resultTotalAdvance);
 #else
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvances(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvances(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 #endif
 }
@@ -273,7 +273,7 @@
                                     jint count, jint contextCount, jint dirFlags,
                                     jfloat* resultAdvances, jfloat& resultTotalAdvance) {
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvancesWithHarfbuzz(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 }
 
@@ -281,7 +281,7 @@
                                     jint count, jint contextCount, jint dirFlags,
                                     jfloat* resultAdvances, jfloat& resultTotalAdvance) {
     // Compute advances and return them
-    RunAdvanceDescription::computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
+    TextLayoutCacheValue::computeAdvancesWithICU(paint, chars, start, count, contextCount, dirFlags,
             resultAdvances, &resultTotalAdvance);
 }
 
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index a7265be..ff13c2b 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -19,14 +19,14 @@
 namespace android {
 
 TextLayoutCache::TextLayoutCache():
-        mCache(GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*>::kUnlimitedCapacity),
+        mCache(GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*>::kUnlimitedCapacity),
         mSize(0), mMaxSize(MB(DEFAULT_TEXT_LAYOUT_CACHE_SIZE_IN_MB)),
         mCacheHitCount(0), mNanosecondsSaved(0) {
     init();
 }
 
 TextLayoutCache::TextLayoutCache(uint32_t max):
-        mCache(GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*>::kUnlimitedCapacity),
+        mCache(GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*>::kUnlimitedCapacity),
         mSize(0), mMaxSize(max),
         mCacheHitCount(0), mNanosecondsSaved(0) {
     init();
@@ -88,12 +88,12 @@
 /**
  *  Callbacks
  */
-void TextLayoutCache::operator()(TextLayoutCacheKey& text, RunAdvanceDescription*& desc) {
+void TextLayoutCache::operator()(TextLayoutCacheKey& text, TextLayoutCacheValue*& desc) {
     if (desc) {
         size_t totalSizeToDelete = text.getSize() + desc->getSize();
         mSize -= totalSizeToDelete;
         if (mDebugEnabled) {
-            LOGD("RunAdvance description deleted, size = %d", totalSizeToDelete);
+            LOGD("Cache value deleted, size = %d", totalSizeToDelete);
         }
         delete desc;
     }
@@ -120,21 +120,21 @@
         startTime = systemTime(SYSTEM_TIME_MONOTONIC);
     }
 
-    TextLayoutCacheKey entry(paint, text, start, count, contextCount, dirFlags);
+    TextLayoutCacheKey key(paint, text, start, count, contextCount, dirFlags);
 
     // Get entry for cache if possible
-    RunAdvanceDescription* desc = mCache.get(entry);
+    TextLayoutCacheValue* value = mCache.get(key);
 
     // Value not found for the entry, we need to add a new value in the cache
-    if (!desc) {
-        desc = new RunAdvanceDescription();
+    if (!value) {
+        value = new TextLayoutCacheValue();
 
         // Compute advances and store them
-        desc->computeAdvances(paint, text, start, count, contextCount, dirFlags);
-        desc->copyResult(outAdvances, outTotalAdvance);
+        value->computeAdvances(paint, text, start, count, contextCount, dirFlags);
+        value->copyResult(outAdvances, outTotalAdvance);
 
         // Don't bother to add in the cache if the entry is too big
-        size_t size = entry.getSize() + desc->getSize();
+        size_t size = key.getSize() + value->getSize();
         if (size <= mMaxSize) {
             // Cleanup to make some room if needed
             if (mSize + size > mMaxSize) {
@@ -152,18 +152,18 @@
             mSize += size;
 
             // Copy the text when we insert the new entry
-            entry.internalTextCopy();
-            mCache.put(entry, desc);
+            key.internalTextCopy();
+            mCache.put(key, value);
 
             if (mDebugEnabled) {
                 // Update timing information for statistics.
-                desc->setElapsedTime(systemTime(SYSTEM_TIME_MONOTONIC) - startTime);
+                value->setElapsedTime(systemTime(SYSTEM_TIME_MONOTONIC) - startTime);
 
                 LOGD("CACHE MISS: Added entry for text='%s' with start=%d, count=%d, "
                         "contextCount=%d, entry size %d bytes, remaining space %d bytes"
                         " - Compute time in nanos: %d",
                         String8(text, contextCount).string(), start, count, contextCount,
-                        size, mMaxSize - mSize, desc->getElapsedTime());
+                        size, mMaxSize - mSize, value->getElapsedTime());
             }
         } else {
             if (mDebugEnabled) {
@@ -172,27 +172,27 @@
                         "entry size %d bytes, remaining space %d bytes"
                         " - Compute time in nanos: %d",
                         String8(text, contextCount).string(), start, count, contextCount,
-                        size, mMaxSize - mSize, desc->getElapsedTime());
+                        size, mMaxSize - mSize, value->getElapsedTime());
             }
-            delete desc;
+            delete value;
         }
     } else {
         // This is a cache hit, just copy the pre-computed results
-        desc->copyResult(outAdvances, outTotalAdvance);
+        value->copyResult(outAdvances, outTotalAdvance);
         if (mDebugEnabled) {
             nsecs_t elapsedTimeThruCacheGet = systemTime(SYSTEM_TIME_MONOTONIC) - startTime;
-            mNanosecondsSaved += (desc->getElapsedTime() - elapsedTimeThruCacheGet);
+            mNanosecondsSaved += (value->getElapsedTime() - elapsedTimeThruCacheGet);
             ++mCacheHitCount;
 
-            if (desc->getElapsedTime() > 0) {
-                float deltaPercent = 100 * ((desc->getElapsedTime() - elapsedTimeThruCacheGet)
-                        / ((float)desc->getElapsedTime()));
+            if (value->getElapsedTime() > 0) {
+                float deltaPercent = 100 * ((value->getElapsedTime() - elapsedTimeThruCacheGet)
+                        / ((float)value->getElapsedTime()));
                 LOGD("CACHE HIT #%d for text='%s' with start=%d, count=%d, contextCount=%d "
                         "- Compute time in nanos: %d - "
                         "Cache get time in nanos: %lld - Gain in percent: %2.2f",
                         mCacheHitCount, String8(text, contextCount).string(), start, count,
                         contextCount,
-                        desc->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent);
+                        value->getElapsedTime(), elapsedTimeThruCacheGet, deltaPercent);
             }
             if (mCacheHitCount % DEFAULT_DUMP_STATS_CACHE_HIT_INTERVAL == 0) {
                 dumpCacheStats();
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index bced40c..8438d78 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -137,16 +137,16 @@
 }; // TextLayoutCacheKey
 
 /*
- * RunAdvanceDescription is the Cache entry
+ * TextLayoutCacheEntry is the Cache entry
  */
-class RunAdvanceDescription {
+class TextLayoutCacheValue {
 public:
-    RunAdvanceDescription() {
+    TextLayoutCacheValue() {
         advances = NULL;
         totalAdvance = 0;
     }
 
-    ~RunAdvanceDescription() {
+    ~TextLayoutCacheValue() {
         delete[] advances;
     }
 
@@ -186,7 +186,7 @@
      * Get the size of the Cache entry
      */
     size_t getSize() {
-        return sizeof(RunAdvanceDescription) + sizeof(jfloat) * count;
+        return sizeof(TextLayoutCacheValue) + sizeof(jfloat) * count;
     }
 
     static void setupShaperItem(HB_ShaperItem* shaperItem, HB_FontRec* font, FontData* fontData,
@@ -396,10 +396,10 @@
         memset(shaperItem->offsets, 0, size * sizeof(shaperItem->offsets[0]));
     }
 
-}; // RunAdvanceDescription
+}; // TextLayoutCacheEntry
 
 
-class TextLayoutCache: public OnEntryRemoved<TextLayoutCacheKey, RunAdvanceDescription*>
+class TextLayoutCache: public OnEntryRemoved<TextLayoutCacheKey, TextLayoutCacheValue*>
 {
 public:
     TextLayoutCache();
@@ -415,7 +415,7 @@
      * Used as a callback when an entry is removed from the cache.
      * Do not invoke directly.
      */
-    void operator()(TextLayoutCacheKey& text, RunAdvanceDescription*& desc);
+    void operator()(TextLayoutCacheKey& text, TextLayoutCacheValue*& desc);
 
     /**
      * Get cache entries
@@ -448,7 +448,7 @@
     Mutex mLock;
     bool mInitialized;
 
-    GenerationCache<TextLayoutCacheKey, RunAdvanceDescription*> mCache;
+    GenerationCache<TextLayoutCacheKey, TextLayoutCacheValue*> mCache;
 
     uint32_t mSize;
     uint32_t mMaxSize;