diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-11 13:26:37 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-11 13:26:37 +0000 |
commit | 64596e5e583f0c64124da1a79e496d6e063c25fa (patch) | |
tree | 1c94e88ba72567b2de962400cb95744923929d20 | |
parent | bb5f6e57d7f331c178addfa3aa0c2162eb5f51cb (diff) | |
download | chromium_src-64596e5e583f0c64124da1a79e496d6e063c25fa.zip chromium_src-64596e5e583f0c64124da1a79e496d6e063c25fa.tar.gz chromium_src-64596e5e583f0c64124da1a79e496d6e063c25fa.tar.bz2 |
Some minor touchups to the new DOM grouping code.
- Explicitly use std::sort not sort, got lucky before?
- Filter out orphan DOM nodes earlier, this shouldn't make a difference.
- Fix some comments to be more accurate and a few bits of style.
Review URL: http://codereview.chromium.org/13742
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6783 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index 17ec4f0f..3bf5b5b 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -29,6 +29,7 @@ #include "config.h" +#include <algorithm> #include <utility> #include <v8.h> @@ -687,8 +688,7 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) it != end; ++it) { Node* node = it->first; - // If the node is in document, put it in the ownerDocument's - // object group. Otherwise, skip it. + // If the node is in document, put it in the ownerDocument's object group. // // If an image element was created by JavaScript "new Image", // it is not in a document. However, if the load event has not @@ -699,23 +699,27 @@ ACTIVE_DOM_OBJECT_TYPES(MAKE_CASE) uintptr_t group_id; if (node->inDocument() || (node->hasTagName(HTMLNames::imgTag) && - !static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent()) ) { + !static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent())) { group_id = reinterpret_cast<uintptr_t>(node->document()); - } else { Node* root = node; - while (root->parent()) { + while (root->parent()) root = root->parent(); - } + + // If the node is alone in its DOM tree (doesn't have a parent or any + // children) then the group will be filtered out later anyway. + if (root == node && !node->hasChildNodes()) + continue; + group_id = reinterpret_cast<uintptr_t>(root); } grouper.append(GrouperPair(group_id, node)); } - // Group by sorting by the group id. This will use the builtin pair sorter, + // Group by sorting by the group id. This will use the std::pair operator<, // which will really sort by both the group id and the Node*. However the // Node* is only involved to sort within a group id, so it will be fine. - sort(grouper.begin(), grouper.end()); + std::sort(grouper.begin(), grouper.end()); // TODO(deanm): Should probably work in iterators here, but indexes were // easier for my simple mind. |