Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: Source/WebCore/inspector/DOMEditor.cpp

Issue 9389003: Merge 107242 - Web Inspector: fix setOuterHTML for the case that adds / removes duplicate. (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1025/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/inspector/DOMEditor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/inspector/DOMEditor.cpp
===================================================================
--- Source/WebCore/inspector/DOMEditor.cpp (revision 107556)
+++ Source/WebCore/inspector/DOMEditor.cpp (working copy)
@@ -45,6 +45,7 @@
#include "Node.h"
#include <wtf/Deque.h>
+#include <wtf/HashTraits.h>
#include <wtf/RefPtr.h>
#include <wtf/SHA1.h>
#include <wtf/text/CString.h>
@@ -259,6 +260,11 @@
}
}
+#ifdef DEBUG_DOM_EDITOR
+ dumpMap(oldMap, "OLD");
+ dumpMap(newMap, "NEW");
+#endif
+
return make_pair(oldMap, newMap);
}
@@ -273,9 +279,16 @@
// 1. First strip everything except for the nodes that retain. Collect pending merges.
HashMap<Digest*, Digest*> merges;
+ HashSet<size_t, WTF::IntHash<size_t>, WTF::UnsignedWithZeroKeyHashTraits<size_t> > usedNewOrdinals;
for (size_t i = 0; i < oldList.size(); ++i) {
- if (oldMap[i].first)
- continue;
+ if (oldMap[i].first) {
+ if (!usedNewOrdinals.contains(oldMap[i].second)) {
+ usedNewOrdinals.add(oldMap[i].second);
+ continue;
+ }
+ oldMap[i].first = 0;
+ oldMap[i].second = 0;
+ }
// Always match <head> and <body> tags with each other - we can't remove them from the DOM
// upon patching.
@@ -306,10 +319,20 @@
}
}
- // Mark retained nodes as used.
+ // Mark retained nodes as used, do not reuse node more than once.
+ HashSet<size_t, WTF::IntHash<size_t>, WTF::UnsignedWithZeroKeyHashTraits<size_t> > usedOldOrdinals;
for (size_t i = 0; i < newList.size(); ++i) {
- if (newMap[i].first)
- markNodeAsUsed(newMap[i].first);
+ if (!newMap[i].first)
+ continue;
+ size_t oldOrdinal = newMap[i].second;
+ if (usedOldOrdinals.contains(oldOrdinal)) {
+ // Do not map node more than once
+ newMap[i].first = 0;
+ newMap[i].second = 0;
+ continue;
+ }
+ usedOldOrdinals.add(oldOrdinal);
+ markNodeAsUsed(newMap[i].first);
}
// Mark <head> and <body> nodes for merge.
@@ -451,6 +474,22 @@
}
}
+#ifdef DEBUG_DOM_EDITOR
+static String nodeName(Node* node)
+{
+ if (node->document()->isXHTMLDocument())
+ return node->nodeName();
+ return node->nodeName().lower();
+}
+
+void DOMEditor::dumpMap(const ResultMap& map, const String& name)
+{
+ fprintf(stderr, "\n\n");
+ for (size_t i = 0; i < map.size(); ++i)
+ fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map[i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map[i].second);
+}
+#endif
+
} // namespace WebCore
#endif // ENABLE(INSPECTOR)
« no previous file with comments | « Source/WebCore/inspector/DOMEditor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698