Title: [130850] trunk/Source/WebCore
Revision
130850
Author
kl...@webkit.org
Date
2012-10-09 22:28:35 -0700 (Tue, 09 Oct 2012)

Log Message

GlyphPageTreeNode should use HashMap<OwnPtr>.
<http://webkit.org/b/98845>

Reviewed by Dan Bernstein.

- Replace manual memory management by OwnPtrs.
- Added a GlyphPageTreeNodeMap typedef to make call sites look a bit nicer.
= Changed some hashmap get()/remove() pairs to use the more efficient take() instead.
- Made the constructor private, it has no external clients.

* platform/graphics/GlyphPageTreeNode.cpp:
(WebCore::GlyphPageTreeNode::getRoot):
(WebCore::GlyphPageTreeNode::pageCount):
(WebCore::GlyphPageTreeNode::getChild):
(WebCore::GlyphPageTreeNode::pruneCustomFontData):
(WebCore::GlyphPageTreeNode::pruneFontData):
(WebCore::GlyphPageTreeNode::showSubtree):
* platform/graphics/GlyphPageTreeNode.h:
(GlyphPageTreeNode):
(WebCore::GlyphPageTreeNode::GlyphPageTreeNode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (130849 => 130850)


--- trunk/Source/WebCore/ChangeLog	2012-10-10 05:25:32 UTC (rev 130849)
+++ trunk/Source/WebCore/ChangeLog	2012-10-10 05:28:35 UTC (rev 130850)
@@ -1,3 +1,26 @@
+2012-10-09  Andreas Kling  <kl...@webkit.org>
+
+        GlyphPageTreeNode should use HashMap<OwnPtr>.
+        <http://webkit.org/b/98845>
+
+        Reviewed by Dan Bernstein.
+
+        - Replace manual memory management by OwnPtrs.
+        - Added a GlyphPageTreeNodeMap typedef to make call sites look a bit nicer.
+        = Changed some hashmap get()/remove() pairs to use the more efficient take() instead.
+        - Made the constructor private, it has no external clients.
+
+        * platform/graphics/GlyphPageTreeNode.cpp:
+        (WebCore::GlyphPageTreeNode::getRoot):
+        (WebCore::GlyphPageTreeNode::pageCount):
+        (WebCore::GlyphPageTreeNode::getChild):
+        (WebCore::GlyphPageTreeNode::pruneCustomFontData):
+        (WebCore::GlyphPageTreeNode::pruneFontData):
+        (WebCore::GlyphPageTreeNode::showSubtree):
+        * platform/graphics/GlyphPageTreeNode.h:
+        (GlyphPageTreeNode):
+        (WebCore::GlyphPageTreeNode::GlyphPageTreeNode):
+
 2012-10-09  Kent Tamura  <tk...@chromium.org>
 
         Sub-fields in input[type=time] should not be focusable if the input is disabled or read-only

Modified: trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp (130849 => 130850)


--- trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp	2012-10-10 05:25:32 UTC (rev 130849)
+++ trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.cpp	2012-10-10 05:28:35 UTC (rev 130850)
@@ -55,17 +55,17 @@
         pageZeroRoot = new GlyphPageTreeNode;
     }
 
-    GlyphPageTreeNode* node = pageNumber ? roots->get(pageNumber) : pageZeroRoot;
-    if (!node) {
-        node = new GlyphPageTreeNode;
+    if (!pageNumber)
+        return pageZeroRoot;
+
+    if (GlyphPageTreeNode* foundNode = roots->get(pageNumber))
+        return foundNode;
+
+    GlyphPageTreeNode* node = new GlyphPageTreeNode;
 #ifndef NDEBUG
-        node->m_pageNumber = pageNumber;
+    node->m_pageNumber = pageNumber;
 #endif
-        if (pageNumber)
-            roots->set(pageNumber, node);
-        else
-            pageZeroRoot = node;
-    }
+    roots->set(pageNumber, node);
     return node;
 }
 
@@ -87,8 +87,8 @@
 size_t GlyphPageTreeNode::pageCount() const
 {
     size_t count = m_page && m_page->owner() == this ? 1 : 0;
-    HashMap<const FontData*, GlyphPageTreeNode*>::const_iterator end = m_children.end();
-    for (HashMap<const FontData*, GlyphPageTreeNode*>::const_iterator it = m_children.begin(); it != end; ++it)
+    GlyphPageTreeNodeMap::const_iterator end = m_children.end();
+    for (GlyphPageTreeNodeMap::const_iterator it = m_children.begin(); it != end; ++it)
         count += it->value->pageCount();
 
     return count;
@@ -119,12 +119,6 @@
         pageZeroRoot->pruneFontData(fontData);
 }
 
-GlyphPageTreeNode::~GlyphPageTreeNode()
-{
-    deleteAllValues(m_children);
-    delete m_systemFallbackChild;
-}
-
 static bool fill(GlyphPage* pageToFill, unsigned offset, unsigned length, UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
 {
 #if ENABLE(SVG_FONTS)
@@ -323,28 +317,28 @@
     ASSERT(fontData || !m_isSystemFallback);
     ASSERT(pageNumber == m_pageNumber);
 
-    GlyphPageTreeNode* child = fontData ? m_children.get(fontData) : m_systemFallbackChild;
-    if (!child) {
-        child = new GlyphPageTreeNode;
-        child->m_parent = this;
-        child->m_level = m_level + 1;
-        if (fontData && fontData->isCustomFont()) {
-            for (GlyphPageTreeNode* curr = this; curr; curr = curr->m_parent)
-                curr->m_customFontCount++;
-        }
+    if (GlyphPageTreeNode* foundChild = fontData ? m_children.get(fontData) : m_systemFallbackChild.get())
+        return foundChild;
 
+    GlyphPageTreeNode* child = new GlyphPageTreeNode;
+    child->m_parent = this;
+    child->m_level = m_level + 1;
+    if (fontData && fontData->isCustomFont()) {
+        for (GlyphPageTreeNode* curr = this; curr; curr = curr->m_parent)
+            curr->m_customFontCount++;
+    }
+
 #ifndef NDEBUG
-        child->m_pageNumber = m_pageNumber;
+    child->m_pageNumber = m_pageNumber;
 #endif
-        if (fontData) {
-            m_children.set(fontData, child);
-            fontData->setMaxGlyphPageTreeLevel(max(fontData->maxGlyphPageTreeLevel(), child->m_level));
-        } else {
-            m_systemFallbackChild = child;
-            child->m_isSystemFallback = true;
-        }
-        child->initializePage(fontData, pageNumber);
+    if (fontData) {
+        m_children.set(fontData, adoptPtr(child));
+        fontData->setMaxGlyphPageTreeLevel(max(fontData->maxGlyphPageTreeLevel(), child->m_level));
+    } else {
+        m_systemFallbackChild = adoptPtr(child);
+        child->m_isSystemFallback = true;
     }
+    child->initializePage(fontData, pageNumber);
     return child;
 }
 
@@ -354,20 +348,19 @@
         return;
         
     // Prune any branch that contains this FontData.
-    GlyphPageTreeNode* node = m_children.get(fontData);
-    if (node) {
-        m_children.remove(fontData);
-        unsigned fontCount = node->m_customFontCount + 1;
-        delete node;
-        for (GlyphPageTreeNode* curr = this; curr; curr = curr->m_parent)
-            curr->m_customFontCount -= fontCount;
+    if (OwnPtr<GlyphPageTreeNode> node = m_children.take(fontData)) {
+        if (unsigned customFontCount = node->m_customFontCount + 1) {
+            for (GlyphPageTreeNode* curr = this; curr; curr = curr->m_parent)
+                curr->m_customFontCount -= customFontCount;
+        }
     }
     
     // Check any branches that remain that still have custom fonts underneath them.
     if (!m_customFontCount)
         return;
-    HashMap<const FontData*, GlyphPageTreeNode*>::iterator end = m_children.end();
-    for (HashMap<const FontData*, GlyphPageTreeNode*>::iterator it = m_children.begin(); it != end; ++it)
+
+    GlyphPageTreeNodeMap::iterator end = m_children.end();
+    for (GlyphPageTreeNodeMap::iterator it = m_children.begin(); it != end; ++it)
         it->value->pruneCustomFontData(fontData);
 }
 
@@ -380,13 +373,8 @@
         m_systemFallbackChild->m_page->clearForFontData(fontData);
 
     // Prune any branch that contains this FontData.
-    HashMap<const FontData*, GlyphPageTreeNode*>::iterator child = m_children.find(fontData);
-    if (child != m_children.end()) {
-        GlyphPageTreeNode* node = child->value;
-        m_children.remove(fontData);
-        unsigned customFontCount = node->m_customFontCount;
-        delete node;
-        if (customFontCount) {
+    if (OwnPtr<GlyphPageTreeNode> node = m_children.take(fontData)) {
+        if (unsigned customFontCount = node->m_customFontCount) {
             for (GlyphPageTreeNode* curr = this; curr; curr = curr->m_parent)
                 curr->m_customFontCount -= customFontCount;
         }
@@ -396,8 +384,8 @@
     if (level > fontData->maxGlyphPageTreeLevel())
         return;
 
-    HashMap<const FontData*, GlyphPageTreeNode*>::iterator end = m_children.end();
-    for (HashMap<const FontData*, GlyphPageTreeNode*>::iterator it = m_children.begin(); it != end; ++it)
+    GlyphPageTreeNodeMap::iterator end = m_children.end();
+    for (GlyphPageTreeNodeMap::iterator it = m_children.begin(); it != end; ++it)
         it->value->pruneFontData(fontData, level);
 }
 
@@ -408,8 +396,8 @@
         indent.fill('\t', level());
         indent.append(0);
 
-        HashMap<const FontData*, GlyphPageTreeNode*>::iterator end = m_children.end();
-        for (HashMap<const FontData*, GlyphPageTreeNode*>::iterator it = m_children.begin(); it != end; ++it) {
+        GlyphPageTreeNodeMap::iterator end = m_children.end();
+        for (GlyphPageTreeNodeMap::iterator it = m_children.begin(); it != end; ++it) {
             printf("%s\t%p %s\n", indent.data(), it->key, it->key->description().utf8().data());
             it->value->showSubtree();
         }

Modified: trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.h (130849 => 130850)


--- trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.h	2012-10-10 05:25:32 UTC (rev 130849)
+++ trunk/Source/WebCore/platform/graphics/GlyphPageTreeNode.h	2012-10-10 05:28:35 UTC (rev 130850)
@@ -32,6 +32,7 @@
 #include "GlyphPage.h"
 #include <string.h>
 #include <wtf/HashMap.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/unicode/Unicode.h>
@@ -69,23 +70,6 @@
 class GlyphPageTreeNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    GlyphPageTreeNode()
-        : m_parent(0)
-        , m_level(0)
-        , m_isSystemFallback(false)
-        , m_customFontCount(0)
-        , m_systemFallbackChild(0)
-#ifndef NDEBUG
-        , m_pageNumber(0)
-#endif
-    {
-    }
-
-    ~GlyphPageTreeNode();
-
-    static HashMap<int, GlyphPageTreeNode*>* roots;
-    static GlyphPageTreeNode* pageZeroRoot;
-
     static GlyphPageTreeNode* getRootChild(const FontData* fontData, unsigned pageNumber)
     {
         return getRoot(pageNumber)->getChild(fontData, pageNumber);
@@ -113,6 +97,17 @@
     size_t pageCount() const;
 
 private:
+    GlyphPageTreeNode()
+        : m_parent(0)
+        , m_level(0)
+        , m_isSystemFallback(false)
+        , m_customFontCount(0)
+#ifndef NDEBUG
+        , m_pageNumber(0)
+#endif
+    {
+    }
+
     static GlyphPageTreeNode* getRoot(unsigned pageNumber);
     void initializePage(const FontData*, unsigned pageNumber);
 
@@ -120,17 +115,23 @@
     void showSubtree();
 #endif
 
+    static HashMap<int, GlyphPageTreeNode*>* roots;
+    static GlyphPageTreeNode* pageZeroRoot;
+
+    typedef HashMap<const FontData*, OwnPtr<GlyphPageTreeNode> > GlyphPageTreeNodeMap;
+
+    GlyphPageTreeNodeMap m_children;
     GlyphPageTreeNode* m_parent;
     RefPtr<GlyphPage> m_page;
     unsigned m_level : 31;
     bool m_isSystemFallback : 1;
     unsigned m_customFontCount;
-    HashMap<const FontData*, GlyphPageTreeNode*> m_children;
-    GlyphPageTreeNode* m_systemFallbackChild;
+    OwnPtr<GlyphPageTreeNode> m_systemFallbackChild;
 
 #ifndef NDEBUG
     unsigned m_pageNumber;
 
+    friend void ::showGlyphPageTrees();
     friend void ::showGlyphPageTree(unsigned pageNumber);
 #endif
 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to