Eagerly update the unichar to glyphID mapping.

In addition, some small cleanups.

BUG=chromium:635005
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2249063005

Review-Url: https://codereview.chromium.org/2249063005
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 6d978a6..40d5997 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -91,12 +91,17 @@
 uint16_t SkGlyphCache::unicharToGlyph(SkUnichar charCode) {
     VALIDATE();
     PackedUnicharID packedUnicharID = SkGlyph::MakeID(charCode);
-    const CharGlyphRec& rec = *this->getCharGlyphRec(packedUnicharID);
+    CharGlyphRec* rec = this->getCharGlyphRec(packedUnicharID);
 
-    if (rec.fPackedUnicharID == packedUnicharID) {
-        return SkGlyph::ID2Code(rec.fPackedGlyphID);
+    if (rec->fPackedUnicharID == packedUnicharID) {
+        // The glyph exists in the unichar to glyph mapping cache. Return it.
+        return SkGlyph::ID2Code(rec->fPackedGlyphID);
     } else {
-        return fScalerContext->charToGlyphID(charCode);
+        // The glyph is not in the unichar to glyph mapping cache. Insert it.
+        rec->fPackedUnicharID = packedUnicharID;
+        uint16_t glyphID = fScalerContext->charToGlyphID(charCode);
+        rec->fPackedGlyphID = SkGlyph::MakeID(glyphID);
+        return glyphID;
     }
 }
 
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index 2a96370..84a32eb 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -227,8 +227,7 @@
     SkGlyph* lookupByChar(SkUnichar id, MetricsType type, SkFixed x = 0, SkFixed y = 0);
 
     // Return a new SkGlyph for the glyph ID and subpixel position id. Limit the amount
-    // of work
-    // using type.
+    // of work using type.
     SkGlyph* allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType type);
 
     static bool DetachProc(const SkGlyphCache*, void*) { return true; }
@@ -238,8 +237,6 @@
 
     void invokeAndRemoveAuxProcs();
 
-    inline static SkGlyphCache* FindTail(SkGlyphCache* head);
-
     static void OffsetResults(const SkGlyph::Intercept* intercept, SkScalar scale,
                               SkScalar xPos, SkScalar* array, int* count);
     static void AddInterval(SkScalar val, SkGlyph::Intercept* intercept);