DOMNamedFlowCollection.cpp [plain text]
#include "config.h"
#include "DOMNamedFlowCollection.h"
#include "WebKitNamedFlow.h"
#include <wtf/text/AtomicStringHash.h>
namespace WebCore {
inline DOMNamedFlowCollection::DOMNamedFlowCollection(Vector<Ref<WebKitNamedFlow>>&& flows)
: m_flows(WTFMove(flows))
{
}
Ref<DOMNamedFlowCollection> DOMNamedFlowCollection::create(Vector<Ref<WebKitNamedFlow>>&& flows)
{
return adoptRef(*new DOMNamedFlowCollection(WTFMove(flows)));
}
DOMNamedFlowCollection::~DOMNamedFlowCollection()
{
}
WebKitNamedFlow* DOMNamedFlowCollection::item(unsigned index) const
{
if (index >= m_flows.size())
return nullptr;
return const_cast<WebKitNamedFlow*>(m_flows[index].ptr());
}
struct DOMNamedFlowCollection::HashFunctions {
static unsigned hash(const WebKitNamedFlow* key) { return AtomicStringHash::hash(key->name()); }
static bool equal(const WebKitNamedFlow* a, const WebKitNamedFlow* b) { return a->name() == b->name(); }
static const bool safeToCompareToEmptyOrDeleted = false;
static unsigned hash(const AtomicString& key) { return AtomicStringHash::hash(key); }
static bool equal(const WebKitNamedFlow* a, const AtomicString& b) { return a->name() == b; }
};
WebKitNamedFlow* DOMNamedFlowCollection::namedItem(const AtomicString& name) const
{
if (m_flowsByName.isEmpty()) {
for (auto& flow : m_flows)
m_flowsByName.add(const_cast<WebKitNamedFlow*>(flow.ptr()));
}
auto it = m_flowsByName.find<HashFunctions>(name);
if (it == m_flowsByName.end())
return nullptr;
return *it;
}
const Vector<AtomicString>& DOMNamedFlowCollection::supportedPropertyNames()
{
if (m_flowNames.isEmpty()) {
m_flowNames.reserveInitialCapacity(m_flows.size());
for (auto& flow : m_flows)
m_flowNames.uncheckedAppend(flow->name());
}
return m_flowNames;
}
}