flutter_flutter/engine/core/dom/WeakNodeMap.cpp
Eric Seidel e0fd75b5ab Make absolute and sort all Sky headers
This caused us to lose our gn check certification. :(

Turns out gn check was just ignoring all the header
paths it didn't understand and so gn check passing
for sky wasn't meaning much.  I tried to straighten
out some of the mess in this CL, but its going to take
several more rounds of massaging before gn check
passes again.  On the bright side (almost) all of
our headers are absolute now.  Turns out my script
(attached to the bug) didn't notice ../ includes
but I'll fix that in the next patch.

R=abarth@chromium.org
BUG=435361

Review URL: https://codereview.chromium.org/746023002
2014-11-20 17:42:05 -08:00

107 lines
2.7 KiB
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/dom/WeakNodeMap.h"
#include "sky/engine/core/dom/Node.h"
namespace blink {
#if !ENABLE(OILPAN)
class NodeToWeakNodeMaps {
public:
bool addedToMap(Node*, WeakNodeMap*);
bool removedFromMap(Node*, WeakNodeMap*);
void nodeDestroyed(Node*);
static NodeToWeakNodeMaps& instance()
{
DEFINE_STATIC_LOCAL(NodeToWeakNodeMaps, self, ());
return self;
}
private:
typedef Vector<WeakNodeMap*, 1> MapList;
typedef HashMap<Node*, OwnPtr<MapList> > NodeToMapList;
NodeToMapList m_nodeToMapList;
};
bool NodeToWeakNodeMaps::addedToMap(Node* node, WeakNodeMap* map)
{
NodeToMapList::AddResult result = m_nodeToMapList.add(node, nullptr);
if (result.isNewEntry)
result.storedValue->value = adoptPtr(new MapList());
result.storedValue->value->append(map);
return result.isNewEntry;
}
bool NodeToWeakNodeMaps::removedFromMap(Node* node, WeakNodeMap* map)
{
NodeToMapList::iterator it = m_nodeToMapList.find(node);
ASSERT(it != m_nodeToMapList.end());
MapList* mapList = it->value.get();
size_t position = mapList->find(map);
ASSERT(position != kNotFound);
mapList->remove(position);
if (mapList->size() == 0) {
m_nodeToMapList.remove(it);
return true;
}
return false;
}
void NodeToWeakNodeMaps::nodeDestroyed(Node* node)
{
OwnPtr<NodeToWeakNodeMaps::MapList> maps = m_nodeToMapList.take(node);
for (size_t i = 0; i < maps->size(); i++)
(*maps)[i]->nodeDestroyed(node);
}
WeakNodeMap::~WeakNodeMap()
{
NodeToWeakNodeMaps& allMaps = NodeToWeakNodeMaps::instance();
for (NodeToValue::iterator it = m_nodeToValue.begin(); it != m_nodeToValue.end(); ++it) {
Node* node = it->key;
if (allMaps.removedFromMap(node, this))
node->clearFlag(Node::HasWeakReferencesFlag);
}
}
void WeakNodeMap::put(Node* node, int value)
{
ASSERT(node && !m_nodeToValue.contains(node));
m_nodeToValue.set(node, value);
m_valueToNode.set(value, node);
NodeToWeakNodeMaps& maps = NodeToWeakNodeMaps::instance();
if (maps.addedToMap(node, this))
node->setFlag(Node::HasWeakReferencesFlag);
}
int WeakNodeMap::value(Node* node)
{
return m_nodeToValue.get(node);
}
Node* WeakNodeMap::node(int value)
{
return m_valueToNode.get(value);
}
void WeakNodeMap::nodeDestroyed(Node* node)
{
int value = m_nodeToValue.take(node);
ASSERT(value);
m_valueToNode.remove(value);
}
void WeakNodeMap::notifyNodeDestroyed(Node* node)
{
NodeToWeakNodeMaps::instance().nodeDestroyed(node);
}
#endif
}