Commit 86c749fe authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Use an AtomicString as key in DocumentOrderedMap

Use an AtomicString as key in DocumentOrderedMap instead of a StringImpl*.
This is safer as the HashMap Traits rely on the StringImpl* to not be a
dangling pointer (it is calling StringImpl::hash()). Using an AtomicString
as key will make sure we don't experience use-after-free such as in Bug
402255.

I ran Bindings/get-element-by-id.html test and did not see any performance
regression.

R=esprehn@chromium.org, morrita@chromium.org
BUG=402255

Review URL: https://codereview.chromium.org/467973003

git-svn-id: svn://svn.chromium.org/blink/trunk@180365 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6b5a2b11
...@@ -71,7 +71,7 @@ void DocumentOrderedMap::add(const AtomicString& key, Element* element) ...@@ -71,7 +71,7 @@ void DocumentOrderedMap::add(const AtomicString& key, Element* element)
ASSERT(key); ASSERT(key);
ASSERT(element); ASSERT(element);
Map::AddResult addResult = m_map.add(key.impl(), adoptPtrWillBeNoop(new MapEntry(element))); Map::AddResult addResult = m_map.add(key, adoptPtrWillBeNoop(new MapEntry(element)));
if (addResult.isNewEntry) if (addResult.isNewEntry)
return; return;
...@@ -87,7 +87,7 @@ void DocumentOrderedMap::remove(const AtomicString& key, Element* element) ...@@ -87,7 +87,7 @@ void DocumentOrderedMap::remove(const AtomicString& key, Element* element)
ASSERT(key); ASSERT(key);
ASSERT(element); ASSERT(element);
Map::iterator it = m_map.find(key.impl()); Map::iterator it = m_map.find(key);
if (it == m_map.end()) if (it == m_map.end())
return; return;
...@@ -112,7 +112,7 @@ inline Element* DocumentOrderedMap::get(const AtomicString& key, const TreeScope ...@@ -112,7 +112,7 @@ inline Element* DocumentOrderedMap::get(const AtomicString& key, const TreeScope
ASSERT(key); ASSERT(key);
ASSERT(scope); ASSERT(scope);
MapEntry* entry = m_map.get(key.impl()); MapEntry* entry = m_map.get(key);
if (!entry) if (!entry)
return 0; return 0;
...@@ -142,7 +142,7 @@ const WillBeHeapVector<RawPtrWillBeMember<Element> >& DocumentOrderedMap::getAll ...@@ -142,7 +142,7 @@ const WillBeHeapVector<RawPtrWillBeMember<Element> >& DocumentOrderedMap::getAll
ASSERT(scope); ASSERT(scope);
DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMember<Element> > >, emptyVector, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMember<Element> >()))); DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMember<Element> > >, emptyVector, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillBeMember<Element> >())));
Map::iterator it = m_map.find(key.impl()); Map::iterator it = m_map.find(key);
if (it == m_map.end()) if (it == m_map.end())
return *emptyVector; return *emptyVector;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "wtf/Forward.h" #include "wtf/Forward.h"
#include "wtf/HashMap.h" #include "wtf/HashMap.h"
#include "wtf/text/AtomicString.h" #include "wtf/text/AtomicString.h"
#include "wtf/text/AtomicStringHash.h"
#include "wtf/text/StringImpl.h" #include "wtf/text/StringImpl.h"
namespace blink { namespace blink {
...@@ -78,19 +79,19 @@ private: ...@@ -78,19 +79,19 @@ private:
WillBeHeapVector<RawPtrWillBeMember<Element> > orderedList; WillBeHeapVector<RawPtrWillBeMember<Element> > orderedList;
}; };
typedef WillBeHeapHashMap<StringImpl*, OwnPtrWillBeMember<MapEntry> > Map; typedef WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<MapEntry> > Map;
mutable Map m_map; mutable Map m_map;
}; };
inline bool DocumentOrderedMap::contains(const AtomicString& id) const inline bool DocumentOrderedMap::contains(const AtomicString& id) const
{ {
return m_map.contains(id.impl()); return m_map.contains(id);
} }
inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const inline bool DocumentOrderedMap::containsMultiple(const AtomicString& id) const
{ {
Map::const_iterator it = m_map.find(id.impl()); Map::const_iterator it = m_map.find(id);
return it != m_map.end() && it->value->count > 1; return it != m_map.end() && it->value->count > 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment