Commit f4694086 authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Change TreeOrderedMap to accept a reference instead of a pointer

This CL also changes a few other related pieces of code to use references
as necessary.

Change-Id: I8aaf0dd00e3f56819244a8b6dbdd6c2f758bee64
Reviewed-on: https://chromium-review.googlesource.com/1175592Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583201}
parent a511c255
...@@ -4452,9 +4452,9 @@ inline void Element::UpdateId(TreeScope& scope, ...@@ -4452,9 +4452,9 @@ inline void Element::UpdateId(TreeScope& scope,
DCHECK_NE(old_id, new_id); DCHECK_NE(old_id, new_id);
if (!old_id.IsEmpty()) if (!old_id.IsEmpty())
scope.RemoveElementById(old_id, this); scope.RemoveElementById(old_id, *this);
if (!new_id.IsEmpty()) if (!new_id.IsEmpty())
scope.AddElementById(new_id, this); scope.AddElementById(new_id, *this);
NamedItemType type = GetNamedItemType(); NamedItemType type = GetNamedItemType();
if (type == NamedItemType::kNameOrId || if (type == NamedItemType::kNameOrId ||
......
...@@ -83,7 +83,7 @@ void SlotAssignment::DidAddSlotInternal(HTMLSlotElement& slot) { ...@@ -83,7 +83,7 @@ void SlotAssignment::DidAddSlotInternal(HTMLSlotElement& slot) {
DCHECK(!old_active || old_active != slot); DCHECK(!old_active || old_active != slot);
// This might invalidate the slot_map's cache. // This might invalidate the slot_map's cache.
slot_map_->Add(slot_name, &slot); slot_map_->Add(slot_name, slot);
// This also ensures that TreeOrderedMap has a cache for the first element. // This also ensures that TreeOrderedMap has a cache for the first element.
HTMLSlotElement* new_active = FindSlotByName(slot_name); HTMLSlotElement* new_active = FindSlotByName(slot_name);
...@@ -130,7 +130,7 @@ void SlotAssignment::DidRemoveSlotInternal( ...@@ -130,7 +130,7 @@ void SlotAssignment::DidRemoveSlotInternal(
HTMLSlotElement* old_active = HTMLSlotElement* old_active =
GetCachedFirstSlotWithoutAccessingNodeTree(slot_name); GetCachedFirstSlotWithoutAccessingNodeTree(slot_name);
DCHECK(old_active); DCHECK(old_active);
slot_map_->Remove(slot_name, &slot); slot_map_->Remove(slot_name, slot);
// This also ensures that TreeOrderedMap has a cache for the first element. // This also ensures that TreeOrderedMap has a cache for the first element.
HTMLSlotElement* new_active = FindSlotByName(slot_name); HTMLSlotElement* new_active = FindSlotByName(slot_name);
DCHECK(!new_active || new_active != slot); DCHECK(!new_active || new_active != slot);
......
...@@ -76,9 +76,8 @@ inline bool KeyMatchesSlotName(const AtomicString& key, ...@@ -76,9 +76,8 @@ inline bool KeyMatchesSlotName(const AtomicString& key,
ToHTMLSlotElement(element).GetName() == key; ToHTMLSlotElement(element).GetName() == key;
} }
void TreeOrderedMap::Add(const AtomicString& key, Element* element) { void TreeOrderedMap::Add(const AtomicString& key, Element& element) {
DCHECK(key); DCHECK(key);
DCHECK(element);
Map::AddResult add_result = map_.insert(key, new MapEntry(element)); Map::AddResult add_result = map_.insert(key, new MapEntry(element));
if (add_result.is_new_entry) if (add_result.is_new_entry)
...@@ -91,9 +90,8 @@ void TreeOrderedMap::Add(const AtomicString& key, Element* element) { ...@@ -91,9 +90,8 @@ void TreeOrderedMap::Add(const AtomicString& key, Element* element) {
entry->ordered_list.clear(); entry->ordered_list.clear();
} }
void TreeOrderedMap::Remove(const AtomicString& key, Element* element) { void TreeOrderedMap::Remove(const AtomicString& key, Element& element) {
DCHECK(key); DCHECK(key);
DCHECK(element);
Map::iterator it = map_.find(key); Map::iterator it = map_.find(key);
if (it == map_.end()) if (it == map_.end())
......
...@@ -50,8 +50,8 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> { ...@@ -50,8 +50,8 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> {
public: public:
static TreeOrderedMap* Create(); static TreeOrderedMap* Create();
void Add(const AtomicString&, Element*); void Add(const AtomicString&, Element&);
void Remove(const AtomicString&, Element*); void Remove(const AtomicString&, Element&);
bool Contains(const AtomicString&) const; bool Contains(const AtomicString&) const;
bool ContainsMultiple(const AtomicString&) const; bool ContainsMultiple(const AtomicString&) const;
...@@ -98,7 +98,7 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> { ...@@ -98,7 +98,7 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> {
class MapEntry : public GarbageCollected<MapEntry> { class MapEntry : public GarbageCollected<MapEntry> {
public: public:
explicit MapEntry(Element* first_element) explicit MapEntry(Element& first_element)
: element(first_element), count(1) {} : element(first_element), count(1) {}
void Trace(blink::Visitor*); void Trace(blink::Visitor*);
......
...@@ -137,7 +137,7 @@ const HeapVector<Member<Element>>& TreeScope::GetAllElementsById( ...@@ -137,7 +137,7 @@ const HeapVector<Member<Element>>& TreeScope::GetAllElementsById(
} }
void TreeScope::AddElementById(const AtomicString& element_id, void TreeScope::AddElementById(const AtomicString& element_id,
Element* element) { Element& element) {
if (!elements_by_id_) if (!elements_by_id_)
elements_by_id_ = TreeOrderedMap::Create(); elements_by_id_ = TreeOrderedMap::Create();
elements_by_id_->Add(element_id, element); elements_by_id_->Add(element_id, element);
...@@ -145,7 +145,7 @@ void TreeScope::AddElementById(const AtomicString& element_id, ...@@ -145,7 +145,7 @@ void TreeScope::AddElementById(const AtomicString& element_id,
} }
void TreeScope::RemoveElementById(const AtomicString& element_id, void TreeScope::RemoveElementById(const AtomicString& element_id,
Element* element) { Element& element) {
if (!elements_by_id_) if (!elements_by_id_)
return; return;
elements_by_id_->Remove(element_id, element); elements_by_id_->Remove(element_id, element);
...@@ -165,8 +165,8 @@ Node* TreeScope::AncestorInThisScope(Node* node) const { ...@@ -165,8 +165,8 @@ Node* TreeScope::AncestorInThisScope(Node* node) const {
return nullptr; return nullptr;
} }
void TreeScope::AddImageMap(HTMLMapElement* image_map) { void TreeScope::AddImageMap(HTMLMapElement& image_map) {
const AtomicString& name = image_map->GetName(); const AtomicString& name = image_map.GetName();
if (!name) if (!name)
return; return;
if (!image_maps_by_name_) if (!image_maps_by_name_)
...@@ -174,10 +174,10 @@ void TreeScope::AddImageMap(HTMLMapElement* image_map) { ...@@ -174,10 +174,10 @@ void TreeScope::AddImageMap(HTMLMapElement* image_map) {
image_maps_by_name_->Add(name, image_map); image_maps_by_name_->Add(name, image_map);
} }
void TreeScope::RemoveImageMap(HTMLMapElement* image_map) { void TreeScope::RemoveImageMap(HTMLMapElement& image_map) {
if (!image_maps_by_name_) if (!image_maps_by_name_)
return; return;
const AtomicString& name = image_map->GetName(); const AtomicString& name = image_map.GetName();
if (!name) if (!name)
return; return;
image_maps_by_name_->Remove(name, image_map); image_maps_by_name_->Remove(name, image_map);
......
...@@ -76,8 +76,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin { ...@@ -76,8 +76,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin {
const AtomicString&) const; const AtomicString&) const;
bool HasElementWithId(const AtomicString& id) const; bool HasElementWithId(const AtomicString& id) const;
bool ContainsMultipleElementsWithId(const AtomicString& id) const; bool ContainsMultipleElementsWithId(const AtomicString& id) const;
void AddElementById(const AtomicString& element_id, Element*); void AddElementById(const AtomicString& element_id, Element&);
void RemoveElementById(const AtomicString& element_id, Element*); void RemoveElementById(const AtomicString& element_id, Element&);
Document& GetDocument() const { Document& GetDocument() const {
DCHECK(document_); DCHECK(document_);
...@@ -86,8 +86,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin { ...@@ -86,8 +86,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin {
Node* AncestorInThisScope(Node*) const; Node* AncestorInThisScope(Node*) const;
void AddImageMap(HTMLMapElement*); void AddImageMap(HTMLMapElement&);
void RemoveImageMap(HTMLMapElement*); void RemoveImageMap(HTMLMapElement&);
HTMLMapElement* GetImageMap(const String& url) const; HTMLMapElement* GetImageMap(const String& url) const;
Element* ElementFromPoint(double x, double y) const; Element* ElementFromPoint(double x, double y) const;
......
...@@ -87,13 +87,13 @@ void HTMLMapElement::ParseAttribute(const AttributeModificationParams& params) { ...@@ -87,13 +87,13 @@ void HTMLMapElement::ParseAttribute(const AttributeModificationParams& params) {
return; return;
} }
if (isConnected()) if (isConnected())
GetTreeScope().RemoveImageMap(this); GetTreeScope().RemoveImageMap(*this);
String map_name = params.new_value; String map_name = params.new_value;
if (map_name[0] == '#') if (map_name[0] == '#')
map_name = map_name.Substring(1); map_name = map_name.Substring(1);
name_ = AtomicString(map_name); name_ = AtomicString(map_name);
if (isConnected()) if (isConnected())
GetTreeScope().AddImageMap(this); GetTreeScope().AddImageMap(*this);
return; return;
} }
...@@ -108,13 +108,13 @@ HTMLCollection* HTMLMapElement::areas() { ...@@ -108,13 +108,13 @@ HTMLCollection* HTMLMapElement::areas() {
Node::InsertionNotificationRequest HTMLMapElement::InsertedInto( Node::InsertionNotificationRequest HTMLMapElement::InsertedInto(
ContainerNode* insertion_point) { ContainerNode* insertion_point) {
if (insertion_point->isConnected()) if (insertion_point->isConnected())
GetTreeScope().AddImageMap(this); GetTreeScope().AddImageMap(*this);
return HTMLElement::InsertedInto(insertion_point); return HTMLElement::InsertedInto(insertion_point);
} }
void HTMLMapElement::RemovedFrom(ContainerNode* insertion_point) { void HTMLMapElement::RemovedFrom(ContainerNode* insertion_point) {
if (insertion_point->isConnected()) if (insertion_point->isConnected())
GetTreeScope().RemoveImageMap(this); GetTreeScope().RemoveImageMap(*this);
HTMLElement::RemovedFrom(insertion_point); HTMLElement::RemovedFrom(insertion_point);
} }
......
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