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,
DCHECK_NE(old_id, new_id);
if (!old_id.IsEmpty())
scope.RemoveElementById(old_id, this);
scope.RemoveElementById(old_id, *this);
if (!new_id.IsEmpty())
scope.AddElementById(new_id, this);
scope.AddElementById(new_id, *this);
NamedItemType type = GetNamedItemType();
if (type == NamedItemType::kNameOrId ||
......
......@@ -83,7 +83,7 @@ void SlotAssignment::DidAddSlotInternal(HTMLSlotElement& slot) {
DCHECK(!old_active || old_active != slot);
// 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.
HTMLSlotElement* new_active = FindSlotByName(slot_name);
......@@ -130,7 +130,7 @@ void SlotAssignment::DidRemoveSlotInternal(
HTMLSlotElement* old_active =
GetCachedFirstSlotWithoutAccessingNodeTree(slot_name);
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.
HTMLSlotElement* new_active = FindSlotByName(slot_name);
DCHECK(!new_active || new_active != slot);
......
......@@ -76,9 +76,8 @@ inline bool KeyMatchesSlotName(const AtomicString& key,
ToHTMLSlotElement(element).GetName() == key;
}
void TreeOrderedMap::Add(const AtomicString& key, Element* element) {
void TreeOrderedMap::Add(const AtomicString& key, Element& element) {
DCHECK(key);
DCHECK(element);
Map::AddResult add_result = map_.insert(key, new MapEntry(element));
if (add_result.is_new_entry)
......@@ -91,9 +90,8 @@ void TreeOrderedMap::Add(const AtomicString& key, Element* element) {
entry->ordered_list.clear();
}
void TreeOrderedMap::Remove(const AtomicString& key, Element* element) {
void TreeOrderedMap::Remove(const AtomicString& key, Element& element) {
DCHECK(key);
DCHECK(element);
Map::iterator it = map_.find(key);
if (it == map_.end())
......
......@@ -50,8 +50,8 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> {
public:
static TreeOrderedMap* Create();
void Add(const AtomicString&, Element*);
void Remove(const AtomicString&, Element*);
void Add(const AtomicString&, Element&);
void Remove(const AtomicString&, Element&);
bool Contains(const AtomicString&) const;
bool ContainsMultiple(const AtomicString&) const;
......@@ -98,7 +98,7 @@ class TreeOrderedMap : public GarbageCollected<TreeOrderedMap> {
class MapEntry : public GarbageCollected<MapEntry> {
public:
explicit MapEntry(Element* first_element)
explicit MapEntry(Element& first_element)
: element(first_element), count(1) {}
void Trace(blink::Visitor*);
......
......@@ -137,7 +137,7 @@ const HeapVector<Member<Element>>& TreeScope::GetAllElementsById(
}
void TreeScope::AddElementById(const AtomicString& element_id,
Element* element) {
Element& element) {
if (!elements_by_id_)
elements_by_id_ = TreeOrderedMap::Create();
elements_by_id_->Add(element_id, element);
......@@ -145,7 +145,7 @@ void TreeScope::AddElementById(const AtomicString& element_id,
}
void TreeScope::RemoveElementById(const AtomicString& element_id,
Element* element) {
Element& element) {
if (!elements_by_id_)
return;
elements_by_id_->Remove(element_id, element);
......@@ -165,8 +165,8 @@ Node* TreeScope::AncestorInThisScope(Node* node) const {
return nullptr;
}
void TreeScope::AddImageMap(HTMLMapElement* image_map) {
const AtomicString& name = image_map->GetName();
void TreeScope::AddImageMap(HTMLMapElement& image_map) {
const AtomicString& name = image_map.GetName();
if (!name)
return;
if (!image_maps_by_name_)
......@@ -174,10 +174,10 @@ void TreeScope::AddImageMap(HTMLMapElement* 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_)
return;
const AtomicString& name = image_map->GetName();
const AtomicString& name = image_map.GetName();
if (!name)
return;
image_maps_by_name_->Remove(name, image_map);
......
......@@ -76,8 +76,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin {
const AtomicString&) const;
bool HasElementWithId(const AtomicString& id) const;
bool ContainsMultipleElementsWithId(const AtomicString& id) const;
void AddElementById(const AtomicString& element_id, Element*);
void RemoveElementById(const AtomicString& element_id, Element*);
void AddElementById(const AtomicString& element_id, Element&);
void RemoveElementById(const AtomicString& element_id, Element&);
Document& GetDocument() const {
DCHECK(document_);
......@@ -86,8 +86,8 @@ class CORE_EXPORT TreeScope : public GarbageCollectedMixin {
Node* AncestorInThisScope(Node*) const;
void AddImageMap(HTMLMapElement*);
void RemoveImageMap(HTMLMapElement*);
void AddImageMap(HTMLMapElement&);
void RemoveImageMap(HTMLMapElement&);
HTMLMapElement* GetImageMap(const String& url) const;
Element* ElementFromPoint(double x, double y) const;
......
......@@ -87,13 +87,13 @@ void HTMLMapElement::ParseAttribute(const AttributeModificationParams& params) {
return;
}
if (isConnected())
GetTreeScope().RemoveImageMap(this);
GetTreeScope().RemoveImageMap(*this);
String map_name = params.new_value;
if (map_name[0] == '#')
map_name = map_name.Substring(1);
name_ = AtomicString(map_name);
if (isConnected())
GetTreeScope().AddImageMap(this);
GetTreeScope().AddImageMap(*this);
return;
}
......@@ -108,13 +108,13 @@ HTMLCollection* HTMLMapElement::areas() {
Node::InsertionNotificationRequest HTMLMapElement::InsertedInto(
ContainerNode* insertion_point) {
if (insertion_point->isConnected())
GetTreeScope().AddImageMap(this);
GetTreeScope().AddImageMap(*this);
return HTMLElement::InsertedInto(insertion_point);
}
void HTMLMapElement::RemovedFrom(ContainerNode* insertion_point) {
if (insertion_point->isConnected())
GetTreeScope().RemoveImageMap(this);
GetTreeScope().RemoveImageMap(*this);
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