<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[149654] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/149654">149654</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2013-05-06 17:45:31 -0700 (Mon, 06 May 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Use OwnPtr instead of deleteAllValues in DocumentMarkerController
https://bugs.webkit.org/show_bug.cgi?id=115655

Reviewed by Andreas Kling.

* dom/DocumentMarkerController.cpp:
(WebCore::DocumentMarkerController::~DocumentMarkerController): Added here
so the destructor isn't implicitly inline.
(WebCore::DocumentMarkerController::detach): Removed now-unneeded code to
call deleteAllValues. Also moved code to set m_possiblyExistingMarkerTypes
to after clearing m_markers to be consistent with how other functions do it.
(WebCore::DocumentMarkerController::addMarker): Changed code to use the
add idiom to avoid double hash table lookup. Changed to use adoptPtr since
the map now contains OwnPtr.
(WebCore::DocumentMarkerController::removeMarkers): Removed explicit calls
to delete list since removing the entry from the map now deletes the list.
Moved the code to check if m_markers has become empty so it's only called
when we actually remove something from m_markers.
(WebCore::DocumentMarkerController::markerContainingPoint): Added get().
(WebCore::DocumentMarkerController::renderedRectsForMarkers): Added get().
(WebCore::DocumentMarkerController::removeMarkers): Changed to use a new
interface to removeMarkersFromList. This eliminated the need to copy the
entire map when removing markers; instead we can just copy the keys.
(WebCore::DocumentMarkerController::removeMarkersFromList): Changed to use
an iterator instead of being passed the key/value pair from the map. Also
rearranged the logic so there is less repeated code and removed some now-
unneeded comments.
(WebCore::DocumentMarkerController::repaintMarkers): Added get().
(WebCore::DocumentMarkerController::invalidateRenderedRectsForMarkersInRect):
Added get().
(WebCore::DocumentMarkerController::showMarkers): Added get().

* dom/DocumentMarkerController.h: Removed implementation of the destructor
that called the detach function; that was just sharing the now-unneeded
call to deleteAllValues. Changed the type of the map to use an OwnPtr for
the value. Changed the interface of removeMarkersFromList to take a map
iterator instead of a key/value pair.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentMarkerControllercpp">trunk/Source/WebCore/dom/DocumentMarkerController.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentMarkerControllerh">trunk/Source/WebCore/dom/DocumentMarkerController.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (149653 => 149654)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-05-07 00:33:05 UTC (rev 149653)
+++ trunk/Source/WebCore/ChangeLog        2013-05-07 00:45:31 UTC (rev 149654)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2013-05-06  Darin Adler  &lt;darin@apple.com&gt;
+
+        Use OwnPtr instead of deleteAllValues in DocumentMarkerController
+        https://bugs.webkit.org/show_bug.cgi?id=115655
+
+        Reviewed by Andreas Kling.
+
+        * dom/DocumentMarkerController.cpp:
+        (WebCore::DocumentMarkerController::~DocumentMarkerController): Added here
+        so the destructor isn't implicitly inline.
+        (WebCore::DocumentMarkerController::detach): Removed now-unneeded code to
+        call deleteAllValues. Also moved code to set m_possiblyExistingMarkerTypes
+        to after clearing m_markers to be consistent with how other functions do it.
+        (WebCore::DocumentMarkerController::addMarker): Changed code to use the
+        add idiom to avoid double hash table lookup. Changed to use adoptPtr since
+        the map now contains OwnPtr.
+        (WebCore::DocumentMarkerController::removeMarkers): Removed explicit calls
+        to delete list since removing the entry from the map now deletes the list.
+        Moved the code to check if m_markers has become empty so it's only called
+        when we actually remove something from m_markers.
+        (WebCore::DocumentMarkerController::markerContainingPoint): Added get().
+        (WebCore::DocumentMarkerController::renderedRectsForMarkers): Added get().
+        (WebCore::DocumentMarkerController::removeMarkers): Changed to use a new
+        interface to removeMarkersFromList. This eliminated the need to copy the
+        entire map when removing markers; instead we can just copy the keys.
+        (WebCore::DocumentMarkerController::removeMarkersFromList): Changed to use
+        an iterator instead of being passed the key/value pair from the map. Also
+        rearranged the logic so there is less repeated code and removed some now-
+        unneeded comments.
+        (WebCore::DocumentMarkerController::repaintMarkers): Added get().
+        (WebCore::DocumentMarkerController::invalidateRenderedRectsForMarkersInRect):
+        Added get().
+        (WebCore::DocumentMarkerController::showMarkers): Added get().
+
+        * dom/DocumentMarkerController.h: Removed implementation of the destructor
+        that called the detach function; that was just sharing the now-unneeded
+        call to deleteAllValues. Changed the type of the map to use an OwnPtr for
+        the value. Changed the interface of removeMarkersFromList to take a map
+        iterator instead of a key/value pair.
+
</ins><span class="cx"> 2013-05-06  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reproducible crash in RenderBoxModelObject::adjustedPositionRelativeToOffsetParent()
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentMarkerControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DocumentMarkerController.cpp (149653 => 149654)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DocumentMarkerController.cpp        2013-05-07 00:33:05 UTC (rev 149653)
+++ trunk/Source/WebCore/dom/DocumentMarkerController.cpp        2013-05-07 00:45:31 UTC (rev 149654)
</span><span class="lines">@@ -33,10 +33,7 @@
</span><span class="cx"> #include &quot;RenderObject.h&quot;
</span><span class="cx"> #include &quot;RenderedDocumentMarker.h&quot;
</span><span class="cx"> #include &quot;TextIterator.h&quot;
</span><del>-
-#ifndef NDEBUG
</del><span class="cx"> #include &lt;stdio.h&gt;
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -50,13 +47,14 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+DocumentMarkerController::~DocumentMarkerController()
+{
+}
+
</ins><span class="cx"> void DocumentMarkerController::detach()
</span><span class="cx"> {
</span><del>-    m_possiblyExistingMarkerTypes = 0;
-    if (m_markers.isEmpty())
-        return;
-    deleteAllValues(m_markers);
</del><span class="cx">     m_markers.clear();
</span><ins>+    m_possiblyExistingMarkerTypes = 0;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DocumentMarkerController::addMarker(Range* range, DocumentMarker::MarkerType type, const String&amp; description)
</span><span class="lines">@@ -134,12 +132,11 @@
</span><span class="cx"> 
</span><span class="cx">     m_possiblyExistingMarkerTypes.add(newMarker.type());
</span><span class="cx"> 
</span><del>-    MarkerList* list = m_markers.get(node);
</del><ins>+    OwnPtr&lt;MarkerList&gt;&amp; list = m_markers.add(node, nullptr).iterator-&gt;value;
</ins><span class="cx"> 
</span><span class="cx">     if (!list) {
</span><del>-        list = new MarkerList;
</del><ins>+        list = adoptPtr(new MarkerList);
</ins><span class="cx">         list-&gt;append(RenderedDocumentMarker(newMarker));
</span><del>-        m_markers.set(node, list);
</del><span class="cx">     } else {
</span><span class="cx">         RenderedDocumentMarker toInsert(newMarker);
</span><span class="cx">         size_t numMarkers = list-&gt;size();
</span><span class="lines">@@ -286,11 +283,9 @@
</span><span class="cx"> 
</span><span class="cx">     if (list-&gt;isEmpty()) {
</span><span class="cx">         m_markers.remove(node);
</span><del>-        delete list;
</del><ins>+        if (m_markers.isEmpty())
+            m_possiblyExistingMarkerTypes = 0;
</ins><span class="cx">     }
</span><del>-    
-    if (m_markers.isEmpty())
-        m_possiblyExistingMarkerTypes = 0;
</del><span class="cx"> 
</span><span class="cx">     // repaint the affected node
</span><span class="cx">     if (docDirty &amp;&amp; node-&gt;renderer())
</span><span class="lines">@@ -307,7 +302,7 @@
</span><span class="cx">     MarkerMap::iterator end = m_markers.end();
</span><span class="cx">     for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != end; ++nodeIterator) {
</span><span class="cx">         // inner loop; process each marker in this node
</span><del>-        MarkerList* list = nodeIterator-&gt;value;
</del><ins>+        MarkerList* list = nodeIterator-&gt;value.get();
</ins><span class="cx">         unsigned markerCount = list-&gt;size();
</span><span class="cx">         for (unsigned markerIndex = 0; markerIndex &lt; markerCount; ++markerIndex) {
</span><span class="cx">             RenderedDocumentMarker&amp; marker = list-&gt;at(markerIndex);
</span><span class="lines">@@ -395,7 +390,7 @@
</span><span class="cx">     MarkerMap::iterator end = m_markers.end();
</span><span class="cx">     for (MarkerMap::iterator nodeIterator = m_markers.begin(); nodeIterator != end; ++nodeIterator) {
</span><span class="cx">         // inner loop; process each marker in this node
</span><del>-        MarkerList* list = nodeIterator-&gt;value;
</del><ins>+        MarkerList* list = nodeIterator-&gt;value.get();
</ins><span class="cx">         unsigned markerCount = list-&gt;size();
</span><span class="cx">         for (unsigned markerIndex = 0; markerIndex &lt; markerCount; ++markerIndex) {
</span><span class="cx">             const RenderedDocumentMarker&amp; marker = list-&gt;at(markerIndex);
</span><span class="lines">@@ -422,7 +417,7 @@
</span><span class="cx">     
</span><span class="cx">     MarkerMap::iterator iterator = m_markers.find(node);
</span><span class="cx">     if (iterator != m_markers.end())
</span><del>-        removeMarkersFromList(node, iterator-&gt;value, markerTypes);
</del><ins>+        removeMarkersFromList(iterator, markerTypes);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DocumentMarkerController::removeMarkers(DocumentMarker::MarkerTypes markerTypes)
</span><span class="lines">@@ -431,25 +426,30 @@
</span><span class="cx">         return;
</span><span class="cx">     ASSERT(!m_markers.isEmpty());
</span><span class="cx"> 
</span><del>-    // outer loop: process each markered node in the document
-    MarkerMap markerMapCopy = m_markers;
-    MarkerMap::iterator end = markerMapCopy.end();
-    for (MarkerMap::iterator i = markerMapCopy.begin(); i != end; ++i)
-        removeMarkersFromList(i-&gt;key.get(), i-&gt;value, markerTypes);
</del><ins>+    Vector&lt;RefPtr&lt;Node&gt; &gt; nodesWithMarkers;
+    copyKeysToVector(m_markers, nodesWithMarkers);
+    unsigned size = nodesWithMarkers.size();
+    for (unsigned i = 0; i &lt; size; ++i) {
+        MarkerMap::iterator iterator = m_markers.find(nodesWithMarkers[i]);
+        if (iterator != m_markers.end())
+            removeMarkersFromList(iterator, markerTypes);
+    }
+
</ins><span class="cx">     m_possiblyExistingMarkerTypes.remove(markerTypes);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-// This function may release node and vectorPair.
-void DocumentMarkerController::removeMarkersFromList(Node* node, MarkerList* list, DocumentMarker::MarkerTypes markerTypes)
</del><ins>+void DocumentMarkerController::removeMarkersFromList(MarkerMap::iterator iterator, DocumentMarker::MarkerTypes markerTypes)
</ins><span class="cx"> {
</span><ins>+    bool needsRepainting = false;
+    bool listCanBeRemoved;
+
</ins><span class="cx">     if (markerTypes == DocumentMarker::AllMarkers()) {
</span><del>-        delete list;
-        m_markers.remove(node);
-        if (RenderObject* renderer = node-&gt;renderer())
-            renderer-&gt;repaint();
</del><ins>+        needsRepainting = true;
+        listCanBeRemoved = true;
</ins><span class="cx">     } else {
</span><del>-        bool needsRepaint = false;
-        for (size_t i = 0; i != list-&gt;size();) {
</del><ins>+        MarkerList* list = iterator-&gt;value.get();
+
+        for (size_t i = 0; i != list-&gt;size(); ) {
</ins><span class="cx">             DocumentMarker marker = list-&gt;at(i);
</span><span class="cx"> 
</span><span class="cx">             // skip nodes that are not of the specified type
</span><span class="lines">@@ -460,26 +460,23 @@
</span><span class="cx"> 
</span><span class="cx">             // pitch the old marker
</span><span class="cx">             list-&gt;remove(i);
</span><del>-            needsRepaint = true;
</del><ins>+            needsRepainting = true;
</ins><span class="cx">             // i now is the index of the next marker
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        // Redraw the node if it changed. Do this before the node is removed from m_markers, since
-        // m_markers might contain the last reference to the node.
-        if (needsRepaint) {
-            RenderObject* renderer = node-&gt;renderer();
-            if (renderer)
-                renderer-&gt;repaint();
-        }
</del><ins>+        listCanBeRemoved = list-&gt;isEmpty();
+    }
</ins><span class="cx"> 
</span><del>-        // delete the node's list if it is now empty
-        if (list-&gt;isEmpty()) {
-            m_markers.remove(node);
-            delete list;
-        }
</del><ins>+    if (needsRepainting) {
+        if (RenderObject* renderer = iterator-&gt;key-&gt;renderer())
+            renderer-&gt;repaint();
</ins><span class="cx">     }
</span><del>-    if (m_markers.isEmpty())
-        m_possiblyExistingMarkerTypes = 0;
</del><ins>+
+    if (listCanBeRemoved) {
+        m_markers.remove(iterator);
+        if (m_markers.isEmpty())
+            m_possiblyExistingMarkerTypes = 0;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DocumentMarkerController::repaintMarkers(DocumentMarker::MarkerTypes markerTypes)
</span><span class="lines">@@ -494,7 +491,7 @@
</span><span class="cx">         Node* node = i-&gt;key.get();
</span><span class="cx"> 
</span><span class="cx">         // inner loop: process each marker in the current node
</span><del>-        MarkerList* list = i-&gt;value;
</del><ins>+        MarkerList* list = i-&gt;value.get();
</ins><span class="cx">         bool nodeNeedsRepaint = false;
</span><span class="cx">         for (size_t i = 0; i != list-&gt;size(); ++i) {
</span><span class="cx">             DocumentMarker marker = list-&gt;at(i);
</span><span class="lines">@@ -522,7 +519,7 @@
</span><span class="cx">     for (MarkerMap::iterator i = m_markers.begin(); i != end; ++i) {
</span><span class="cx"> 
</span><span class="cx">         // inner loop: process each rect in the current node
</span><del>-        MarkerList* list = i-&gt;value;
</del><ins>+        MarkerList* list = i-&gt;value.get();
</ins><span class="cx">         for (size_t listIndex = 0; listIndex &lt; list-&gt;size(); ++listIndex)
</span><span class="cx">             list-&gt;at(listIndex).invalidate(r);
</span><span class="cx">     }
</span><span class="lines">@@ -673,7 +670,7 @@
</span><span class="cx">     for (MarkerMap::const_iterator nodeIterator = m_markers.begin(); nodeIterator != end; ++nodeIterator) {
</span><span class="cx">         Node* node = nodeIterator-&gt;key.get();
</span><span class="cx">         fprintf(stderr, &quot;%p&quot;, node);
</span><del>-        MarkerList* list = nodeIterator-&gt;value;
</del><ins>+        MarkerList* list = nodeIterator-&gt;value.get();
</ins><span class="cx">         for (unsigned markerIndex = 0; markerIndex &lt; list-&gt;size(); ++markerIndex) {
</span><span class="cx">             const DocumentMarker&amp; marker = list-&gt;at(markerIndex);
</span><span class="cx">             fprintf(stderr, &quot; %d:[%d:%d](%d)&quot;, marker.type(), marker.startOffset(), marker.endOffset(), marker.activeMatch());
</span><span class="lines">@@ -686,7 +683,6 @@
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> void showDocumentMarkers(const WebCore::DocumentMarkerController* controller)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentMarkerControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DocumentMarkerController.h (149653 => 149654)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DocumentMarkerController.h        2013-05-07 00:33:05 UTC (rev 149653)
+++ trunk/Source/WebCore/dom/DocumentMarkerController.h        2013-05-07 00:45:31 UTC (rev 149654)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx"> public:
</span><span class="cx"> 
</span><span class="cx">     DocumentMarkerController();
</span><del>-    ~DocumentMarkerController() { detach(); }
</del><ins>+    ~DocumentMarkerController();
</ins><span class="cx"> 
</span><span class="cx">     void detach();
</span><span class="cx">     void addMarker(Range*, DocumentMarker::MarkerType);
</span><span class="lines">@@ -87,9 +87,9 @@
</span><span class="cx">     void addMarker(Node*, const DocumentMarker&amp;);
</span><span class="cx"> 
</span><span class="cx">     typedef Vector&lt;RenderedDocumentMarker&gt; MarkerList;
</span><del>-    typedef HashMap&lt;RefPtr&lt;Node&gt;, MarkerList*&gt; MarkerMap;
</del><ins>+    typedef HashMap&lt;RefPtr&lt;Node&gt;, OwnPtr&lt;MarkerList&gt; &gt; MarkerMap;
</ins><span class="cx">     bool possiblyHasMarkers(DocumentMarker::MarkerTypes);
</span><del>-    void removeMarkersFromList(Node*, MarkerList*, DocumentMarker::MarkerTypes);
</del><ins>+    void removeMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
</ins><span class="cx"> 
</span><span class="cx">     MarkerMap m_markers;
</span><span class="cx">     // Provide a quick way to determine whether a particular marker type is absent without going through the map.
</span></span></pre>
</div>
</div>

</body>
</html>