Use more references instead of pointers in DocumentOrderedMap
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Oct 2013 02:59:02 +0000 (02:59 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Oct 2013 02:59:02 +0000 (02:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122368

Reviewed by Andreas Kling.

Use AtomicStringImpl& instead of AtomicString* or AtomicString& to eliminate
assertions and nullity checks.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
* bindings/js/JSHTMLDocumentCustom.cpp:
(WebCore::JSHTMLDocument::canGetItemsForName):
(WebCore::JSHTMLDocument::nameGetter):
* dom/Document.cpp:
(WebCore::Document::addImageElementByLowercasedUsemap):
(WebCore::Document::removeImageElementByLowercasedUsemap):
(WebCore::Document::imageElementByLowercasedUsemap):
* dom/Document.h:
* dom/DocumentOrderedMap.cpp:
(WebCore::keyMatchesId):
(WebCore::keyMatchesName):
(WebCore::keyMatchesMapName):
(WebCore::keyMatchesLowercasedMapName):
(WebCore::keyMatchesLowercasedUsemap):
(WebCore::keyMatchesLabelForAttribute):
(WebCore::keyMatchesWindowNamedItem):
(WebCore::keyMatchesDocumentNamedItem):
(WebCore::DocumentOrderedMap::add):
(WebCore::DocumentOrderedMap::remove):
(WebCore::DocumentOrderedMap::get):
(WebCore::DocumentOrderedMap::getElementById):
(WebCore::DocumentOrderedMap::getElementByName):
(WebCore::DocumentOrderedMap::getElementByMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
(WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
(WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
(WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
(WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
(WebCore::DocumentOrderedMap::getAllElementsById):
* dom/DocumentOrderedMap.h:
(WebCore::DocumentOrderedMap::containsSingle):
(WebCore::DocumentOrderedMap::contains):
(WebCore::DocumentOrderedMap::containsMultiple):
* dom/Element.cpp:
(WebCore::Element::updateNameForTreeScope):
(WebCore::Element::updateNameForDocument):
(WebCore::Element::updateIdForTreeScope):
(WebCore::Element::updateIdForDocument):
(WebCore::Element::updateLabel):
* dom/IdTargetObserverRegistry.cpp:
(WebCore::IdTargetObserverRegistry::notifyObserversInternal):
* dom/IdTargetObserverRegistry.h:
(WebCore::IdTargetObserverRegistry::notifyObservers):
* dom/TreeScope.cpp:
(WebCore::TreeScope::getElementById):
(WebCore::TreeScope::getAllElementsById):
(WebCore::TreeScope::addElementById):
(WebCore::TreeScope::removeElementById):
(WebCore::TreeScope::getElementByName):
(WebCore::TreeScope::addElementByName):
(WebCore::TreeScope::removeElementByName):
(WebCore::TreeScope::addImageMap):
(WebCore::TreeScope::removeImageMap):
(WebCore::TreeScope::getImageMap):
(WebCore::TreeScope::addLabel):
(WebCore::TreeScope::removeLabel):
(WebCore::TreeScope::labelElementForId):
* dom/TreeScope.h:
(WebCore::TreeScope::hasElementWithId):
(WebCore::TreeScope::containsMultipleElementsWithId):
(WebCore::TreeScope::hasElementWithName):
(WebCore::TreeScope::containsMultipleElementsWithName):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::namedItem):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::addDocumentNamedItem):
(WebCore::HTMLDocument::removeDocumentNamedItem):
(WebCore::HTMLDocument::addWindowNamedItem):
(WebCore::HTMLDocument::removeWindowNamedItem):
* html/HTMLDocument.h:
(WebCore::HTMLDocument::documentNamedItem):
(WebCore::HTMLDocument::hasDocumentNamedItem):
(WebCore::HTMLDocument::documentNamedItemContainsMultipleElements):
(WebCore::HTMLDocument::windowNamedItem):
(WebCore::HTMLDocument::hasWindowNamedItem):
(WebCore::HTMLDocument::windowNamedItemContainsMultipleElements):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
(WebCore::HTMLImageElement::insertedInto):
(WebCore::HTMLImageElement::removedFrom):
* html/HTMLMapElement.cpp:
(WebCore::HTMLMapElement::imageElement):
(WebCore::HTMLMapElement::parseAttribute):
(WebCore::HTMLMapElement::insertedInto):
(WebCore::HTMLMapElement::removedFrom):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156940 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentOrderedMap.cpp
Source/WebCore/dom/DocumentOrderedMap.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/IdTargetObserverRegistry.cpp
Source/WebCore/dom/IdTargetObserverRegistry.h
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/dom/TreeScope.h
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLDocument.cpp
Source/WebCore/html/HTMLDocument.h
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLMapElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp

index 1f65fefbb51dc32ef1e83c84ede33cbffa1100d1..44bd3a5178c79f9c8fe48f4bbc10de857329444b 100644 (file)
@@ -1,3 +1,105 @@
+2013-10-04  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Use more references instead of pointers in DocumentOrderedMap
+        https://bugs.webkit.org/show_bug.cgi?id=122368
+
+        Reviewed by Andreas Kling.
+
+        Use AtomicStringImpl& instead of AtomicString* or AtomicString& to eliminate
+        assertions and nullity checks.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::namedItemGetter):
+        (WebCore::JSDOMWindow::getOwnPropertySlot):
+        (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+        * bindings/js/JSHTMLDocumentCustom.cpp:
+        (WebCore::JSHTMLDocument::canGetItemsForName):
+        (WebCore::JSHTMLDocument::nameGetter):
+        * dom/Document.cpp:
+        (WebCore::Document::addImageElementByLowercasedUsemap):
+        (WebCore::Document::removeImageElementByLowercasedUsemap):
+        (WebCore::Document::imageElementByLowercasedUsemap):
+        * dom/Document.h:
+        * dom/DocumentOrderedMap.cpp:
+        (WebCore::keyMatchesId):
+        (WebCore::keyMatchesName):
+        (WebCore::keyMatchesMapName):
+        (WebCore::keyMatchesLowercasedMapName):
+        (WebCore::keyMatchesLowercasedUsemap):
+        (WebCore::keyMatchesLabelForAttribute):
+        (WebCore::keyMatchesWindowNamedItem):
+        (WebCore::keyMatchesDocumentNamedItem):
+        (WebCore::DocumentOrderedMap::add):
+        (WebCore::DocumentOrderedMap::remove):
+        (WebCore::DocumentOrderedMap::get):
+        (WebCore::DocumentOrderedMap::getElementById):
+        (WebCore::DocumentOrderedMap::getElementByName):
+        (WebCore::DocumentOrderedMap::getElementByMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedMapName):
+        (WebCore::DocumentOrderedMap::getElementByLowercasedUsemap):
+        (WebCore::DocumentOrderedMap::getElementByLabelForAttribute):
+        (WebCore::DocumentOrderedMap::getElementByWindowNamedItem):
+        (WebCore::DocumentOrderedMap::getElementByDocumentNamedItem):
+        (WebCore::DocumentOrderedMap::getAllElementsById):
+        * dom/DocumentOrderedMap.h:
+        (WebCore::DocumentOrderedMap::containsSingle):
+        (WebCore::DocumentOrderedMap::contains):
+        (WebCore::DocumentOrderedMap::containsMultiple):
+        * dom/Element.cpp:
+        (WebCore::Element::updateNameForTreeScope):
+        (WebCore::Element::updateNameForDocument):
+        (WebCore::Element::updateIdForTreeScope):
+        (WebCore::Element::updateIdForDocument):
+        (WebCore::Element::updateLabel):
+        * dom/IdTargetObserverRegistry.cpp:
+        (WebCore::IdTargetObserverRegistry::notifyObserversInternal):
+        * dom/IdTargetObserverRegistry.h:
+        (WebCore::IdTargetObserverRegistry::notifyObservers):
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::getElementById):
+        (WebCore::TreeScope::getAllElementsById):
+        (WebCore::TreeScope::addElementById):
+        (WebCore::TreeScope::removeElementById):
+        (WebCore::TreeScope::getElementByName):
+        (WebCore::TreeScope::addElementByName):
+        (WebCore::TreeScope::removeElementByName):
+        (WebCore::TreeScope::addImageMap):
+        (WebCore::TreeScope::removeImageMap):
+        (WebCore::TreeScope::getImageMap):
+        (WebCore::TreeScope::addLabel):
+        (WebCore::TreeScope::removeLabel):
+        (WebCore::TreeScope::labelElementForId):
+        * dom/TreeScope.h:
+        (WebCore::TreeScope::hasElementWithId):
+        (WebCore::TreeScope::containsMultipleElementsWithId):
+        (WebCore::TreeScope::hasElementWithName):
+        (WebCore::TreeScope::containsMultipleElementsWithName):
+        * html/HTMLCollection.cpp:
+        (WebCore::HTMLCollection::namedItem):
+        * html/HTMLDocument.cpp:
+        (WebCore::HTMLDocument::addDocumentNamedItem):
+        (WebCore::HTMLDocument::removeDocumentNamedItem):
+        (WebCore::HTMLDocument::addWindowNamedItem):
+        (WebCore::HTMLDocument::removeWindowNamedItem):
+        * html/HTMLDocument.h:
+        (WebCore::HTMLDocument::documentNamedItem):
+        (WebCore::HTMLDocument::hasDocumentNamedItem):
+        (WebCore::HTMLDocument::documentNamedItemContainsMultipleElements):
+        (WebCore::HTMLDocument::windowNamedItem):
+        (WebCore::HTMLDocument::hasWindowNamedItem):
+        (WebCore::HTMLDocument::windowNamedItemContainsMultipleElements):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseAttribute):
+        (WebCore::HTMLImageElement::insertedInto):
+        (WebCore::HTMLImageElement::removedFrom):
+        * html/HTMLMapElement.cpp:
+        (WebCore::HTMLMapElement::imageElement):
+        (WebCore::HTMLMapElement::parseAttribute):
+        (WebCore::HTMLMapElement::insertedInto):
+        (WebCore::HTMLMapElement::removedFrom):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+
 2013-10-04  Andreas Kling  <akling@apple.com>
 
         CTTE: PolicyChecker backpointer to Frame should be a reference.
index 190be483ae83f257d7c56252fe940f7bc82648cd..d4067c2e3c906f6a2ce3ef174e36e929f3e954ff 100644 (file)
@@ -96,17 +96,17 @@ static JSValue namedItemGetter(ExecState* exec, JSValue slotBase, PropertyName p
     ASSERT(document->isHTMLDocument());
 
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    if (!atomicPropertyName || !toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName))
+    if (!atomicPropertyName || !toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName))
         return jsUndefined();
 
-    if (UNLIKELY(toHTMLDocument(document)->windowNamedItemContainsMultipleElements(atomicPropertyName))) {
+    if (UNLIKELY(toHTMLDocument(document)->windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
         ASSERT(!collection->isEmpty());
         ASSERT(!collection->hasExactlyOneItem());
         return toJS(exec, thisObj->globalObject(), WTF::getPtr(collection));
     }
 
-    return toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(atomicPropertyName));
+    return toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(*atomicPropertyName));
 }
 
 bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
@@ -246,7 +246,7 @@ bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, Property
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName)) {
+        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
@@ -322,7 +322,7 @@ bool JSDOMWindow::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, u
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(atomicPropertyName)) {
+        if (atomicPropertyName && toHTMLDocument(document)->hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
index 98608a280bda06db9c63822b2dfb8543e9976df2..8734473bf6c40310578ff4ed251bc3817a40fdae 100644 (file)
@@ -54,7 +54,7 @@ using namespace HTMLNames;
 bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* document, PropertyName propertyName)
 {
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    return atomicPropertyName && document->hasDocumentNamedItem(atomicPropertyName);
+    return atomicPropertyName && document->hasDocumentNamedItem(*atomicPropertyName);
 }
 
 JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName)
@@ -63,22 +63,23 @@ JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, PropertyNa
     HTMLDocument* document = thisObj->impl();
 
     AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-    if (!atomicPropertyName || !document->hasDocumentNamedItem(atomicPropertyName))
+    if (!atomicPropertyName || !document->hasDocumentNamedItem(*atomicPropertyName))
         return jsUndefined();
 
-    if (UNLIKELY(document->documentNamedItemContainsMultipleElements(atomicPropertyName))) {
+    if (UNLIKELY(document->documentNamedItemContainsMultipleElements(*atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->documentNamedItems(atomicPropertyName);
         ASSERT(!collection->isEmpty());
         ASSERT(!collection->hasExactlyOneItem());
         return toJS(exec, thisObj->globalObject(), WTF::getPtr(collection));
     }
 
-    Node* node = document->documentNamedItem(atomicPropertyName);
-    Frame* frame;
-    if (node->hasTagName(iframeTag) && (frame = toHTMLIFrameElement(node)->contentFrame()))
-        return toJS(exec, frame);
+    Element* element = document->documentNamedItem(*atomicPropertyName);
+    if (UNLIKELY(element->hasTagName(iframeTag))) {
+        if (Frame* frame = toHTMLIFrameElement(element)->contentFrame())
+            return toJS(exec, frame);
+    }
 
-    return toJS(exec, thisObj->globalObject(), node);
+    return toJS(exec, thisObj->globalObject(), element);
 }
 
 // Custom attributes
index 551afb8d842a1a9bfea707905d858a0ffa46ca58..c55e2843ee8e3a154b3a3ea39917511ff1b3b3a3 100644 (file)
@@ -707,19 +707,19 @@ void Document::invalidateAccessKeyMap()
     m_elementsByAccessKey.clear();
 }
 
-void Document::addImageElementByLowercasedUsemap(const AtomicString& name, HTMLImageElement& element)
+void Document::addImageElementByLowercasedUsemap(const AtomicStringImpl& name, HTMLImageElement& element)
 {
-    return m_imagesByUsemap.add(name.impl(), &element);
+    return m_imagesByUsemap.add(nameelement);
 }
 
-void Document::removeImageElementByLowercasedUsemap(const AtomicString& name, HTMLImageElement& element)
+void Document::removeImageElementByLowercasedUsemap(const AtomicStringImpl& name, HTMLImageElement& element)
 {
-    return m_imagesByUsemap.remove(name.impl(), &element);
+    return m_imagesByUsemap.remove(nameelement);
 }
 
-HTMLImageElement* Document::imageElementByLowercasedUsemap(const AtomicString& name) const
+HTMLImageElement* Document::imageElementByLowercasedUsemap(const AtomicStringImpl& name) const
 {
-    return m_imagesByUsemap.getElementByLowercasedUsemap(name.impl(), this);
+    return m_imagesByUsemap.getElementByLowercasedUsemap(name, *this);
 }
 
 SelectorQueryCache& Document::selectorQueryCache()
index 9760d55bda4f06eaaf5101398126e1df84a23e5a..6a2494bb33ceea91671e2541b2a7a743feacfbe1 100644 (file)
@@ -258,9 +258,9 @@ public:
     Element* getElementByAccessKey(const String& key);
     void invalidateAccessKeyMap();
 
-    void addImageElementByLowercasedUsemap(const AtomicString&, HTMLImageElement&);
-    void removeImageElementByLowercasedUsemap(const AtomicString&, HTMLImageElement&);
-    HTMLImageElement* imageElementByLowercasedUsemap(const AtomicString&) const;
+    void addImageElementByLowercasedUsemap(const AtomicStringImpl&, HTMLImageElement&);
+    void removeImageElementByLowercasedUsemap(const AtomicStringImpl&, HTMLImageElement&);
+    HTMLImageElement* imageElementByLowercasedUsemap(const AtomicStringImpl&) const;
 
     SelectorQueryCache& selectorQueryCache();
 
index 25631c78e83049d8bb797489de024d059c970128..6249ec1528df9ddb057a78b7fe49990b5035d34c 100644 (file)
@@ -44,45 +44,45 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-inline bool keyMatchesId(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesId(const AtomicStringImpl& key, Element* element)
 {
-    return element->getIdAttribute().impl() == key;
+    return element->getIdAttribute().impl() == &key;
 }
 
-inline bool keyMatchesName(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesName(const AtomicStringImpl& key, Element* element)
 {
-    return element->getNameAttribute().impl() == key;
+    return element->getNameAttribute().impl() == &key;
 }
 
-inline bool keyMatchesMapName(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesMapName(const AtomicStringImpl& key, Element* element)
 {
-    return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().impl() == key;
+    return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().impl() == &key;
 }
 
-inline bool keyMatchesLowercasedMapName(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesLowercasedMapName(const AtomicStringImpl& key, Element* element)
 {
-    return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().lower().impl() == key;
+    return isHTMLMapElement(element) && toHTMLMapElement(element)->getName().lower().impl() == &key;
 }
 
-inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesLowercasedUsemap(const AtomicStringImpl& key, Element* element)
 {
     // FIXME: HTML5 specification says we should match both image and object elements.
-    return isHTMLImageElement(element) && toHTMLImageElement(element)->matchesLowercasedUsemap(*key);
+    return isHTMLImageElement(element) && toHTMLImageElement(element)->matchesLowercasedUsemap(key);
 }
 
-inline bool keyMatchesLabelForAttribute(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesLabelForAttribute(const AtomicStringImpl& key, Element* element)
 {
-    return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == key;
+    return isHTMLLabelElement(element) && element->getAttribute(forAttr).impl() == &key;
 }
 
-inline bool keyMatchesWindowNamedItem(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesWindowNamedItem(const AtomicStringImpl& key, Element* element)
 {
-    return WindowNameCollection::nodeMatches(element, key);
+    return WindowNameCollection::nodeMatches(element, &key);
 }
 
-inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl* key, Element* element)
+inline bool keyMatchesDocumentNamedItem(const AtomicStringImpl& key, Element* element)
 {
-    return DocumentNameCollection::nodeMatches(element, key);
+    return DocumentNameCollection::nodeMatches(element, &key);
 }
 
 void DocumentOrderedMap::clear()
@@ -90,12 +90,9 @@ void DocumentOrderedMap::clear()
     m_map.clear();
 }
 
-void DocumentOrderedMap::add(const AtomicStringImpl* key, Element* element)
+void DocumentOrderedMap::add(const AtomicStringImpl& key, Element& element)
 {
-    ASSERT(key);
-    ASSERT(element);
-
-    Map::AddResult addResult = m_map.add(key, MapEntry(element));
+    Map::AddResult addResult = m_map.add(&key, MapEntry(&element));
     if (addResult.isNewEntry)
         return;
 
@@ -106,37 +103,31 @@ void DocumentOrderedMap::add(const AtomicStringImpl* key, Element* element)
     entry.orderedList.clear();
 }
 
-void DocumentOrderedMap::remove(const AtomicStringImpl* key, Element* element)
+void DocumentOrderedMap::remove(const AtomicStringImpl& key, Element& element)
 {
-    ASSERT(key);
-    ASSERT(element);
-
     m_map.checkConsistency();
-    Map::iterator it = m_map.find(key);
+    auto it = m_map.find(&key);
     ASSERT(it != m_map.end());
     MapEntry& entry = it->value;
 
     ASSERT(entry.count);
     if (entry.count == 1) {
-        ASSERT(!entry.element || entry.element == element);
+        ASSERT(!entry.element || entry.element == &element);
         m_map.remove(it);
     } else {
-        if (entry.element == element)
+        if (entry.element == &element)
             entry.element = 0;
         entry.count--;
         entry.orderedList.clear(); // FIXME: Remove the element instead if there are only few items left.
     }
 }
 
-template<bool keyMatches(const AtomicStringImpl*, Element*)>
-inline Element* DocumentOrderedMap::get(const AtomicStringImpl* key, const TreeScope* scope) const
+template<bool keyMatches(const AtomicStringImpl&, Element*)>
+inline Element* DocumentOrderedMap::get(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    ASSERT(key);
-    ASSERT(scope);
-
     m_map.checkConsistency();
 
-    Map::iterator it = m_map.find(key);
+    auto it = m_map.find(&key);
     if (it == m_map.end())
         return 0;
 
@@ -146,7 +137,7 @@ inline Element* DocumentOrderedMap::get(const AtomicStringImpl* key, const TreeS
         return entry.element;
 
     // We know there's at least one node that matches; iterate to find the first one.
-    for (Element* element = ElementTraversal::firstWithin(scope->rootNode()); element; element = ElementTraversal::next(element)) {
+    for (Element* element = ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
         if (!keyMatches(key, element))
             continue;
         entry.element = element;
@@ -156,54 +147,51 @@ inline Element* DocumentOrderedMap::get(const AtomicStringImpl* key, const TreeS
     return 0;
 }
 
-Element* DocumentOrderedMap::getElementById(const AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementById(const AtomicStringImpl& key, const TreeScope& scope) const
 {
     return get<keyMatchesId>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
     return get<keyMatchesName>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl* key, const TreeScope* scope) const
+HTMLMapElement* DocumentOrderedMap::getElementByMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesMapName>(key, scope);
+    return toHTMLMapElement(get<keyMatchesMapName>(key, scope));
 }
 
-Element* DocumentOrderedMap::getElementByLowercasedMapName(const AtomicStringImpl* key, const TreeScope* scope) const
+HTMLMapElement* DocumentOrderedMap::getElementByLowercasedMapName(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesLowercasedMapName>(key, scope);
+    return toHTMLMapElement(get<keyMatchesLowercasedMapName>(key, scope));
 }
 
-HTMLImageElement* DocumentOrderedMap::getElementByLowercasedUsemap(const AtomicStringImpl* key, const TreeScope* scope) const
+HTMLImageElement* DocumentOrderedMap::getElementByLowercasedUsemap(const AtomicStringImpl& key, const TreeScope& scope) const
 {
     return toHTMLImageElement(get<keyMatchesLowercasedUsemap>(key, scope));
 }
 
-Element* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl* key, const TreeScope* scope) const
+HTMLLabelElement* DocumentOrderedMap::getElementByLabelForAttribute(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    return get<keyMatchesLabelForAttribute>(key, scope);
+    return toHTMLLabelElement(get<keyMatchesLabelForAttribute>(key, scope));
 }
 
-Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByWindowNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
 {
     return get<keyMatchesWindowNamedItem>(key, scope);
 }
 
-Element* DocumentOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl* key, const TreeScope* scope) const
+Element* DocumentOrderedMap::getElementByDocumentNamedItem(const AtomicStringImpl& key, const TreeScope& scope) const
 {
     return get<keyMatchesDocumentNamedItem>(key, scope);
 }
 
-const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStringImpl* key, const TreeScope* scope) const
+const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStringImpl& key, const TreeScope& scope) const
 {
-    ASSERT(key);
-    ASSERT(scope);
-
     m_map.checkConsistency();
 
-    Map::iterator it = m_map.find(key);
+    auto it = m_map.find(&key);
     if (it == m_map.end())
         return 0;
 
@@ -214,7 +202,7 @@ const Vector<Element*>* DocumentOrderedMap::getAllElementsById(const AtomicStrin
 
     if (entry.orderedList.isEmpty()) {
         entry.orderedList.reserveCapacity(entry.count);
-        for (Element* element = entry.element ? entry.element : ElementTraversal::firstWithin(scope->rootNode()); element; element = ElementTraversal::next(element)) {
+        for (Element* element = entry.element ? entry.element : ElementTraversal::firstWithin(scope.rootNode()); element; element = ElementTraversal::next(element)) {
             if (!keyMatchesId(key, element))
                 continue;
             entry.orderedList.append(element);
index 1e32a347c8361c0ff613c9313ced620fd451d2a3..0a93742376f7d9fabcf6af8598597c1a9f66adc4 100644 (file)
@@ -40,34 +40,36 @@ namespace WebCore {
 
 class Element;
 class HTMLImageElement;
+class HTMLLabelElement;
+class HTMLMapElement;
 class TreeScope;
 
 class DocumentOrderedMap {
 public:
-    void add(const AtomicStringImpl*, Element*);
-    void remove(const AtomicStringImpl*, Element*);
+    void add(const AtomicStringImpl&, Element&);
+    void remove(const AtomicStringImpl&, Element&);
     void clear();
 
-    bool contains(const AtomicStringImpl*) const;
-    bool containsSingle(const AtomicStringImpl*) const;
-    bool containsMultiple(const AtomicStringImpl*) const;
+    bool contains(const AtomicStringImpl&) const;
+    bool containsSingle(const AtomicStringImpl&) const;
+    bool containsMultiple(const AtomicStringImpl&) const;
 
     // concrete instantiations of the get<>() method template
-    Element* getElementById(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByName(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByMapName(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByLowercasedMapName(const AtomicStringImpl*, const TreeScope*) const;
-    HTMLImageElement* getElementByLowercasedUsemap(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByLabelForAttribute(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByWindowNamedItem(const AtomicStringImpl*, const TreeScope*) const;
-    Element* getElementByDocumentNamedItem(const AtomicStringImpl*, const TreeScope*) const;
+    Element* getElementById(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByName(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLMapElement* getElementByMapName(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLMapElement* getElementByLowercasedMapName(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLImageElement* getElementByLowercasedUsemap(const AtomicStringImpl&, const TreeScope&) const;
+    HTMLLabelElement* getElementByLabelForAttribute(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByWindowNamedItem(const AtomicStringImpl&, const TreeScope&) const;
+    Element* getElementByDocumentNamedItem(const AtomicStringImpl&, const TreeScope&) const;
 
-    const Vector<Element*>* getAllElementsById(const AtomicStringImpl*, const TreeScope*) const;
+    const Vector<Element*>* getAllElementsById(const AtomicStringImpl&, const TreeScope&) const;
 
     void checkConsistency() const;
 
 private:
-    template<bool keyMatches(const AtomicStringImpl*, Element*)> Element* get(const AtomicStringImpl*, const TreeScope*) const;
+    template<bool keyMatches(const AtomicStringImpl&, Element*)> Element* get(const AtomicStringImpl&, const TreeScope&) const;
 
     struct MapEntry {
         MapEntry()
@@ -89,20 +91,20 @@ private:
     mutable Map m_map;
 };
 
-inline bool DocumentOrderedMap::containsSingle(const AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::containsSingle(const AtomicStringImpl& id) const
 {
-    Map::const_iterator it = m_map.find(id);
+    auto it = m_map.find(&id);
     return it != m_map.end() && it->value.count == 1;
 }
 
-inline bool DocumentOrderedMap::contains(const AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::contains(const AtomicStringImpl& id) const
 {
-    return m_map.contains(id);
+    return m_map.contains(&id);
 }
 
-inline bool DocumentOrderedMap::containsMultiple(const AtomicStringImpl* id) const
+inline bool DocumentOrderedMap::containsMultiple(const AtomicStringImpl& id) const
 {
-    Map::const_iterator it = m_map.find(id);
+    auto it = m_map.find(&id);
     return it != m_map.end() && it->value.count > 1;
 }
 
index e66c95d07183e87268a1c7acc0293a4299d41658..083f36d2193a86bf2486d7547df9a245b7d7fa1b 100644 (file)
@@ -2785,9 +2785,9 @@ void Element::updateNameForTreeScope(TreeScope* scope, const AtomicString& oldNa
     ASSERT(oldName != newName);
 
     if (!oldName.isEmpty())
-        scope->removeElementByName(oldName, this);
+        scope->removeElementByName(*oldName.impl(), *this);
     if (!newName.isEmpty())
-        scope->addElementByName(newName, this);
+        scope->addElementByName(*newName.impl(), *this);
 }
 
 void Element::updateNameForDocument(HTMLDocument& document, const AtomicString& oldName, const AtomicString& newName)
@@ -2798,17 +2798,17 @@ void Element::updateNameForDocument(HTMLDocument& document, const AtomicString&
     if (WindowNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
         const AtomicString& id = WindowNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
         if (!oldName.isEmpty() && oldName != id)
-            document.removeWindowNamedItem(oldName, this);
+            document.removeWindowNamedItem(*oldName.impl(), *this);
         if (!newName.isEmpty() && newName != id)
-            document.addWindowNamedItem(newName, this);
+            document.addWindowNamedItem(*newName.impl(), *this);
     }
 
     if (DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this)) {
         const AtomicString& id = DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this) ? getIdAttribute() : nullAtom;
         if (!oldName.isEmpty() && oldName != id)
-            document.removeDocumentNamedItem(oldName, this);
+            document.removeDocumentNamedItem(*oldName.impl(), *this);
         if (!newName.isEmpty() && newName != id)
-            document.addDocumentNamedItem(newName, this);
+            document.addDocumentNamedItem(*newName.impl(), *this);
     }
 }
 
@@ -2835,9 +2835,9 @@ void Element::updateIdForTreeScope(TreeScope* scope, const AtomicString& oldId,
     ASSERT(oldId != newId);
 
     if (!oldId.isEmpty())
-        scope->removeElementById(oldId, this);
+        scope->removeElementById(*oldId.impl(), *this);
     if (!newId.isEmpty())
-        scope->addElementById(newId, this);
+        scope->addElementById(*newId.impl(), *this);
 }
 
 void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition condition)
@@ -2848,17 +2848,17 @@ void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& ol
     if (WindowNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
         const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && WindowNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
         if (!oldId.isEmpty() && oldId != name)
-            document.removeWindowNamedItem(oldId, this);
+            document.removeWindowNamedItem(*oldId.impl(), *this);
         if (!newId.isEmpty() && newId != name)
-            document.addWindowNamedItem(newId, this);
+            document.addWindowNamedItem(*newId.impl(), *this);
     }
 
     if (DocumentNameCollection::nodeMatchesIfIdAttributeMatch(this)) {
         const AtomicString& name = condition == UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute && DocumentNameCollection::nodeMatchesIfNameAttributeMatch(this) ? getNameAttribute() : nullAtom;
         if (!oldId.isEmpty() && oldId != name)
-            document.removeDocumentNamedItem(oldId, this);
+            document.removeDocumentNamedItem(*oldId.impl(), *this);
         if (!newId.isEmpty() && newId != name)
-            document.addDocumentNamedItem(newId, this);
+            document.addDocumentNamedItem(*newId.impl(), *this);
     }
 }
 
@@ -2873,9 +2873,9 @@ void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeV
         return;
 
     if (!oldForAttributeValue.isEmpty())
-        scope->removeLabel(oldForAttributeValue, toHTMLLabelElement(this));
+        scope->removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
     if (!newForAttributeValue.isEmpty())
-        scope->addLabel(newForAttributeValue, toHTMLLabelElement(this));
+        scope->addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
 }
 
 void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
index aafa8a2d1b530b7d0f3e3670558e8c96b948afb8..914dd485daed41a652f7189712bca8dc7cd8cd8c 100644 (file)
@@ -60,12 +60,11 @@ void IdTargetObserverRegistry::removeObserver(const AtomicString& id, IdTargetOb
         m_registry.remove(iter);
 }
 
-void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id)
+void IdTargetObserverRegistry::notifyObserversInternal(const AtomicStringImpl& id)
 {
-    ASSERT(!id.isEmpty());
     ASSERT(!m_registry.isEmpty());
 
-    m_notifyingObserversInSet = m_registry.get(id.impl());
+    m_notifyingObserversInSet = m_registry.get(&id);
     if (!m_notifyingObserversInSet)
         return;
 
@@ -77,7 +76,7 @@ void IdTargetObserverRegistry::notifyObserversInternal(const AtomicString& id)
     }
 
     if (m_notifyingObserversInSet->isEmpty())
-        m_registry.remove(id.impl());
+        m_registry.remove(&id);
 
     m_notifyingObserversInSet = 0;
 }
index ef5d662b2f27613942556251b605597b35b5d51f..ba74a2b46a46cfc29c3f334b90d9f5f0d07442e0 100644 (file)
@@ -42,23 +42,31 @@ class IdTargetObserverRegistry {
 public:
     static PassOwnPtr<IdTargetObserverRegistry> create();
     void notifyObservers(const AtomicString& id);
+    void notifyObservers(const AtomicStringImpl& id);
 
 private:
     IdTargetObserverRegistry() : m_notifyingObserversInSet(0) { }
     void addObserver(const AtomicString& id, IdTargetObserver*);
     void removeObserver(const AtomicString& id, IdTargetObserver*);
-    void notifyObserversInternal(const AtomicString& id);
+    void notifyObserversInternal(const AtomicStringImpl& id);
 
     typedef HashSet<IdTargetObserver*> ObserverSet;
-    typedef HashMap<AtomicStringImpl*, OwnPtr<ObserverSet> > IdToObserverSetMap;
+    typedef HashMap<const AtomicStringImpl*, OwnPtr<ObserverSet> > IdToObserverSetMap;
     IdToObserverSetMap m_registry;
     ObserverSet* m_notifyingObserversInSet;
 };
 
 inline void IdTargetObserverRegistry::notifyObservers(const AtomicString& id)
+{
+    if (!id.isEmpty())
+        return notifyObservers(*id.impl());
+}
+
+inline void IdTargetObserverRegistry::notifyObservers(const AtomicStringImpl& id)
 {
     ASSERT(!m_notifyingObserversInSet);
-    if (id.isEmpty() || m_registry.isEmpty())
+    ASSERT(id.length());
+    if (m_registry.isEmpty())
         return;
     IdTargetObserverRegistry::notifyObserversInternal(id);
 }
index e1e1b0e6a90f510c2173a134545428b3baa85a45..32d8a3387581cb09d9d438821a4563c374d1ae26 100644 (file)
@@ -144,7 +144,7 @@ Element* TreeScope::getElementById(const AtomicString& elementId) const
         return 0;
     if (!m_elementsById)
         return 0;
-    return m_elementsById->getElementById(elementId.impl(), this);
+    return m_elementsById->getElementById(*elementId.impl(), *this);
 }
 
 const Vector<Element*>* TreeScope::getAllElementsById(const AtomicString& elementId) const
@@ -153,22 +153,22 @@ const Vector<Element*>* TreeScope::getAllElementsById(const AtomicString& elemen
         return 0;
     if (!m_elementsById)
         return 0;
-    return m_elementsById->getAllElementsById(elementId.impl(), this);
+    return m_elementsById->getAllElementsById(*elementId.impl(), *this);
 }
 
-void TreeScope::addElementById(const AtomicString& elementId, Element* element)
+void TreeScope::addElementById(const AtomicStringImpl& elementId, Element& element)
 {
     if (!m_elementsById)
         m_elementsById = adoptPtr(new DocumentOrderedMap);
-    m_elementsById->add(elementId.impl(), element);
+    m_elementsById->add(elementId, element);
     m_idTargetObserverRegistry->notifyObservers(elementId);
 }
 
-void TreeScope::removeElementById(const AtomicString& elementId, Element* element)
+void TreeScope::removeElementById(const AtomicStringImpl& elementId, Element& element)
 {
     if (!m_elementsById)
         return;
-    m_elementsById->remove(elementId.impl(), element);
+    m_elementsById->remove(elementId, element);
     m_idTargetObserverRegistry->notifyObservers(elementId);
 }
 
@@ -178,21 +178,21 @@ Element* TreeScope::getElementByName(const AtomicString& name) const
         return 0;
     if (!m_elementsByName)
         return 0;
-    return m_elementsByName->getElementByName(name.impl(), this);
+    return m_elementsByName->getElementByName(*name.impl(), *this);
 }
 
-void TreeScope::addElementByName(const AtomicString& name, Element* element)
+void TreeScope::addElementByName(const AtomicStringImpl& name, Element& element)
 {
     if (!m_elementsByName)
         m_elementsByName = adoptPtr(new DocumentOrderedMap);
-    m_elementsByName->add(name.impl(), element);
+    m_elementsByName->add(name, element);
 }
 
-void TreeScope::removeElementByName(const AtomicString& name, Element* element)
+void TreeScope::removeElementByName(const AtomicStringImpl& name, Element& element)
 {
     if (!m_elementsByName)
         return;
-    m_elementsByName->remove(name.impl(), element);
+    m_elementsByName->remove(name, element);
 }
 
 Node* TreeScope::ancestorInThisScope(Node* node) const
@@ -209,24 +209,24 @@ Node* TreeScope::ancestorInThisScope(Node* node) const
     return 0;
 }
 
-void TreeScope::addImageMap(HTMLMapElement* imageMap)
+void TreeScope::addImageMap(HTMLMapElement& imageMap)
 {
-    AtomicStringImpl* name = imageMap->getName().impl();
+    AtomicStringImpl* name = imageMap.getName().impl();
     if (!name)
         return;
     if (!m_imageMapsByName)
         m_imageMapsByName = adoptPtr(new DocumentOrderedMap);
-    m_imageMapsByName->add(name, imageMap);
+    m_imageMapsByName->add(*name, imageMap);
 }
 
-void TreeScope::removeImageMap(HTMLMapElement* imageMap)
+void TreeScope::removeImageMap(HTMLMapElement& imageMap)
 {
     if (!m_imageMapsByName)
         return;
-    AtomicStringImpl* name = imageMap->getName().impl();
+    AtomicStringImpl* name = imageMap.getName().impl();
     if (!name)
         return;
-    m_imageMapsByName->remove(name, imageMap);
+    m_imageMapsByName->remove(*name, imageMap);
 }
 
 HTMLMapElement* TreeScope::getImageMap(const String& url) const
@@ -237,9 +237,13 @@ HTMLMapElement* TreeScope::getImageMap(const String& url) const
         return 0;
     size_t hashPos = url.find('#');
     String name = (hashPos == notFound ? url : url.substring(hashPos + 1)).impl();
-    if (rootNode()->document().isHTMLDocument())
-        return toHTMLMapElement(m_imageMapsByName->getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
-    return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString(name).impl(), this));
+    if (name.isEmpty())
+        return 0;
+    if (rootNode()->document().isHTMLDocument()) {
+        AtomicString lowercasedName = name.lower();
+        return m_imageMapsByName->getElementByLowercasedMapName(*lowercasedName.impl(), *this);
+    }
+    return m_imageMapsByName->getElementByMapName(*AtomicString(name).impl(), *this);
 }
 
 Node* nodeFromPoint(Document* document, int x, int y, LayoutPoint* localPoint)
@@ -278,16 +282,16 @@ Element* TreeScope::elementFromPoint(int x, int y) const
     return toElement(node);
 }
 
-void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
+void TreeScope::addLabel(const AtomicStringImpl& forAttributeValue, HTMLLabelElement& element)
 {
     ASSERT(m_labelsByForAttribute);
-    m_labelsByForAttribute->add(forAttributeValue.impl(), element);
+    m_labelsByForAttribute->add(forAttributeValue, element);
 }
 
-void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
+void TreeScope::removeLabel(const AtomicStringImpl& forAttributeValue, HTMLLabelElement& element)
 {
     ASSERT(m_labelsByForAttribute);
-    m_labelsByForAttribute->remove(forAttributeValue.impl(), element);
+    m_labelsByForAttribute->remove(forAttributeValue, element);
 }
 
 HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeValue)
@@ -303,11 +307,11 @@ HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeV
         for (auto label = labelDescendants.begin(), end = labelDescendants.end(); label != end; ++label) {
             const AtomicString& forValue = label->fastGetAttribute(forAttr);
             if (!forValue.isEmpty())
-                addLabel(forValue, &*label);
+                addLabel(*forValue.impl(), *label);
         }
     }
 
-    return toHTMLLabelElement(m_labelsByForAttribute->getElementByLabelForAttribute(forAttributeValue.impl(), this));
+    return m_labelsByForAttribute->getElementByLabelForAttribute(*forAttributeValue.impl(), *this);
 }
 
 DOMSelection* TreeScope::getSelection() const
index 0acf2c2a5b0ae5f6149355109db81ad3a6f9222e..e4afcb0a48b314e33a1b4acaafdd8dc52f39a0d3 100644 (file)
@@ -57,31 +57,31 @@ public:
     Element* focusedElement();
     Element* getElementById(const AtomicString&) const;
     const Vector<Element*>* getAllElementsById(const AtomicString&) const;
-    bool hasElementWithId(AtomicStringImpl* id) const;
+    bool hasElementWithId(const AtomicStringImpl&) const;
     bool containsMultipleElementsWithId(const AtomicString& id) const;
-    void addElementById(const AtomicString& elementId, Element*);
-    void removeElementById(const AtomicString& elementId, Element*);
+    void addElementById(const AtomicStringImpl& elementId, Element&);
+    void removeElementById(const AtomicStringImpl& elementId, Element&);
 
     Element* getElementByName(const AtomicString&) const;
-    bool hasElementWithName(AtomicStringImpl*) const;
+    bool hasElementWithName(const AtomicStringImpl&) const;
     bool containsMultipleElementsWithName(const AtomicString&) const;
-    void addElementByName(const AtomicString&, Element*);
-    void removeElementByName(const AtomicString&, Element*);
+    void addElementByName(const AtomicStringImpl&, Element&);
+    void removeElementByName(const AtomicStringImpl&, Element&);
 
     Document* documentScope() const { return m_documentScope; }
 
     Node* ancestorInThisScope(Node*) const;
 
-    void addImageMap(HTMLMapElement*);
-    void removeImageMap(HTMLMapElement*);
+    void addImageMap(HTMLMapElement&);
+    void removeImageMap(HTMLMapElement&);
     HTMLMapElement* getImageMap(const String& url) const;
 
     Element* elementFromPoint(int x, int y) const;
 
     // For accessibility.
     bool shouldCacheLabelsByForAttribute() const { return m_labelsByForAttribute; }
-    void addLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
-    void removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
+    void addLabel(const AtomicStringImpl& forAttributeValue, HTMLLabelElement&);
+    void removeLabel(const AtomicStringImpl& forAttributeValue, HTMLLabelElement&);
     HTMLLabelElement* labelElementForId(const AtomicString& forAttributeValue);
 
     DOMSelection* getSelection() const;
@@ -174,26 +174,24 @@ private:
     mutable RefPtr<DOMSelection> m_selection;
 };
 
-inline bool TreeScope::hasElementWithId(AtomicStringImpl* id) const
+inline bool TreeScope::hasElementWithId(const AtomicStringImpl& id) const
 {
-    ASSERT(id);
     return m_elementsById && m_elementsById->contains(id);
 }
 
 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) const
 {
-    return m_elementsById && m_elementsById->containsMultiple(id.impl());
+    return m_elementsById && id.impl() && m_elementsById->containsMultiple(*id.impl());
 }
 
-inline bool TreeScope::hasElementWithName(AtomicStringImpl* id) const
+inline bool TreeScope::hasElementWithName(const AtomicStringImpl& id) const
 {
-    ASSERT(id);
     return m_elementsByName && m_elementsByName->contains(id);
 }
 
 inline bool TreeScope::containsMultipleElementsWithName(const AtomicString& name) const
 {
-    return m_elementsByName && m_elementsByName->containsMultiple(name.impl());
+    return m_elementsByName && name.impl() && m_elementsByName->containsMultiple(*name.impl());
 }
 
 Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0);
index acbf2b9705fcc50dfc58a296040f526374377837..508284e54082497cfc8bda0add99be101ce70d12 100644 (file)
@@ -582,10 +582,10 @@ Node* HTMLCollection::namedItem(const AtomicString& name) const
     if (!overridesItemAfter() && root->isInTreeScope()) {
         TreeScope* treeScope = root->treeScope();
         Element* candidate = 0;
-        if (treeScope->hasElementWithId(name.impl())) {
+        if (treeScope->hasElementWithId(*name.impl())) {
             if (!treeScope->containsMultipleElementsWithId(name))
                 candidate = treeScope->getElementById(name);
-        } else if (treeScope->hasElementWithName(name.impl())) {
+        } else if (treeScope->hasElementWithName(*name.impl())) {
             if (!treeScope->containsMultipleElementsWithName(name)) {
                 candidate = treeScope->getElementByName(name);
                 if (candidate && type() == DocAll && (!candidate->isHTMLElement() || !nameShouldBeVisibleInDocumentAll(toHTMLElement(candidate))))
index 338f46f17fbe73421caf9a7e3bc213c079f6ee29..6adf6085beb0466e6ec3a7eb21c346cb245eee8b 100644 (file)
@@ -356,24 +356,24 @@ static HashSet<AtomicStringImpl*>* createHtmlCaseInsensitiveAttributesSet()
     return attrSet;
 }
 
-void HTMLDocument::addDocumentNamedItem(const AtomicString& name, Element* item)
+void HTMLDocument::addDocumentNamedItem(const AtomicStringImpl& name, Element& item)
 {
-    m_documentNamedItem.add(name.impl(), item);
+    m_documentNamedItem.add(name, item);
 }
 
-void HTMLDocument::removeDocumentNamedItem(const AtomicString& name, Element* item)
+void HTMLDocument::removeDocumentNamedItem(const AtomicStringImpl& name, Element& item)
 {
-    m_documentNamedItem.remove(name.impl(), item);
+    m_documentNamedItem.remove(name, item);
 }
 
-void HTMLDocument::addWindowNamedItem(const AtomicString& name, Element* item)
+void HTMLDocument::addWindowNamedItem(const AtomicStringImpl& name, Element& item)
 {
-    m_windowNamedItem.add(name.impl(), item);
+    m_windowNamedItem.add(name, item);
 }
 
-void HTMLDocument::removeWindowNamedItem(const AtomicString& name, Element* item)
+void HTMLDocument::removeWindowNamedItem(const AtomicStringImpl& name, Element& item)
 {
-    m_windowNamedItem.remove(name.impl(), item);
+    m_windowNamedItem.remove(name, item);
 }
 
 bool HTMLDocument::isCaseSensitiveAttribute(const QualifiedName& attributeName)
index 0479bd5f8f26a08924fe2cba5457f88d18f36876..57a07ec7138bf4bbebc3c6e411f7a346509d1e38 100644 (file)
@@ -65,17 +65,17 @@ public:
     void captureEvents();
     void releaseEvents();
 
-    Element* documentNamedItem(const AtomicStringImpl* name) const { return m_documentNamedItem.getElementByDocumentNamedItem(name, this); }
-    bool hasDocumentNamedItem(const AtomicStringImpl* name) const { return m_documentNamedItem.contains(name); }
-    bool documentNamedItemContainsMultipleElements(const AtomicStringImpl* name) const { return m_documentNamedItem.containsMultiple(name); }
-    void addDocumentNamedItem(const AtomicString&, Element*);
-    void removeDocumentNamedItem(const AtomicString&, Element*);
-
-    Element* windowNamedItem(const AtomicStringImpl* name) const { return m_windowNamedItem.getElementByWindowNamedItem(name, this); }
-    bool hasWindowNamedItem(const AtomicStringImpl* name) const { return m_windowNamedItem.contains(name); }
-    bool windowNamedItemContainsMultipleElements(const AtomicStringImpl* name) const { return m_windowNamedItem.containsMultiple(name); }
-    void addWindowNamedItem(const AtomicString&, Element*);
-    void removeWindowNamedItem(const AtomicString&, Element*);
+    Element* documentNamedItem(const AtomicStringImpl& name) const { return m_documentNamedItem.getElementByDocumentNamedItem(name, *this); }
+    bool hasDocumentNamedItem(const AtomicStringImpl& name) const { return m_documentNamedItem.contains(name); }
+    bool documentNamedItemContainsMultipleElements(const AtomicStringImpl& name) const { return m_documentNamedItem.containsMultiple(name); }
+    void addDocumentNamedItem(const AtomicStringImpl&, Element&);
+    void removeDocumentNamedItem(const AtomicStringImpl&, Element&);
+
+    Element* windowNamedItem(const AtomicStringImpl& name) const { return m_windowNamedItem.getElementByWindowNamedItem(name, *this); }
+    bool hasWindowNamedItem(const AtomicStringImpl& name) const { return m_windowNamedItem.contains(name); }
+    bool windowNamedItemContainsMultipleElements(const AtomicStringImpl& name) const { return m_windowNamedItem.containsMultiple(name); }
+    void addWindowNamedItem(const AtomicStringImpl&, Element&);
+    void removeWindowNamedItem(const AtomicStringImpl&, Element&);
 
     static bool isCaseSensitiveAttribute(const QualifiedName&);
 
index fc8359248521b1ac063c60f3d05ee4bd37344181..e6cb45535ba9014d46d7ca5467258c45895fcda4 100644 (file)
@@ -130,7 +130,7 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
             return;
 
         if (!m_lowercasedUsemap.isNull())
-            document().removeImageElementByLowercasedUsemap(m_lowercasedUsemap, *this);
+            document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
 
         // The HTMLImageElement's useMap() value includes the '#' symbol at the beginning, which has to be stripped off.
         // FIXME: We should check that the first character is '#'.
@@ -142,7 +142,7 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
             m_lowercasedUsemap = nullAtom;
 
         if (!m_lowercasedUsemap.isNull())
-            document().addImageElementByLowercasedUsemap(m_lowercasedUsemap, *this);
+            document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
     } else if (name == onbeforeloadAttr)
         setAttributeEventListener(eventNames().beforeloadEvent, name, value);
     else if (name == compositeAttr) {
@@ -158,9 +158,9 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
                 const AtomicString& id = getIdAttribute();
                 if (!id.isEmpty() && id != getNameAttribute()) {
                     if (willHaveName)
-                        document->addDocumentNamedItem(id, this);
+                        document->addDocumentNamedItem(*id.impl(), *this);
                     else
-                        document->removeDocumentNamedItem(id, this);
+                        document->removeDocumentNamedItem(*id.impl(), *this);
                 }
             }
         }
@@ -225,7 +225,7 @@ Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode&
     }
 
     if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
-        document().addImageElementByLowercasedUsemap(m_lowercasedUsemap, *this);
+        document().addImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
 
     // If we have been inserted from a renderer-less document,
     // our loader may have not fetched the image, so do it now.
@@ -241,7 +241,7 @@ void HTMLImageElement::removedFrom(ContainerNode& insertionPoint)
         m_form->removeImgElement(this);
 
     if (insertionPoint.inDocument() && !m_lowercasedUsemap.isNull())
-        document().removeImageElementByLowercasedUsemap(m_lowercasedUsemap, *this);
+        document().removeImageElementByLowercasedUsemap(*m_lowercasedUsemap.impl(), *this);
 
     m_form = 0;
     HTMLElement::removedFrom(insertionPoint);
index abf6ef995ed9c5485068fbc7d1e1a2d3c92a3457..d677c4b6451fb52ec647632e318526427bea6185 100644 (file)
@@ -79,7 +79,11 @@ bool HTMLMapElement::mapMouseEvent(LayoutPoint location, const LayoutSize& size,
 
 HTMLImageElement* HTMLMapElement::imageElement()
 {
-    return document().imageElementByLowercasedUsemap(m_name.lower());
+    if (m_name.isEmpty())
+        return 0;
+    AtomicString lowercasedName = m_name.lower();
+    ASSERT(lowercasedName.impl());
+    return document().imageElementByLowercasedUsemap(*lowercasedName.impl());
 }
 
 void HTMLMapElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
@@ -95,13 +99,13 @@ void HTMLMapElement::parseAttribute(const QualifiedName& name, const AtomicStrin
                 return;
         }
         if (inDocument())
-            treeScope()->removeImageMap(this);
+            treeScope()->removeImageMap(*this);
         String mapName = value;
         if (mapName[0] == '#')
             mapName = mapName.substring(1);
         m_name = document().isHTMLDocument() ? mapName.lower() : mapName;
         if (inDocument())
-            treeScope()->addImageMap(this);
+            treeScope()->addImageMap(*this);
 
         return;
     }
@@ -117,14 +121,14 @@ PassRefPtr<HTMLCollection> HTMLMapElement::areas()
 Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode& insertionPoint)
 {
     if (insertionPoint.inDocument())
-        treeScope()->addImageMap(this);
+        treeScope()->addImageMap(*this);
     return HTMLElement::insertedInto(insertionPoint);
 }
 
 void HTMLMapElement::removedFrom(ContainerNode& insertionPoint)
 {
     if (insertionPoint.inDocument())
-        treeScope()->removeImageMap(this);
+        treeScope()->removeImageMap(*this);
     HTMLElement::removedFrom(insertionPoint);
 }
 
index 1f2c9b239396ab52cf5b62e773fa11e5e667bc43..43caf3bf2a438790d22c468b0ec786ece2bf2d31 100644 (file)
@@ -427,17 +427,17 @@ void HTMLObjectElement::updateDocNamedItem()
         const AtomicString& id = getIdAttribute();
         if (!id.isEmpty()) {
             if (isNamedItem)
-                document->addDocumentNamedItem(id, this);
+                document->addDocumentNamedItem(*id.impl(), *this);
             else
-                document->removeDocumentNamedItem(id, this);
+                document->removeDocumentNamedItem(*id.impl(), *this);
         }
 
         const AtomicString& name = getNameAttribute();
         if (!name.isEmpty() && id != name) {
             if (isNamedItem)
-                document->addDocumentNamedItem(name, this);
+                document->addDocumentNamedItem(*name.impl(), *this);
             else
-                document->removeDocumentNamedItem(name, this);
+                document->removeDocumentNamedItem(*name.impl(), *this);
         }
     }
     m_docNamedItem = isNamedItem;