diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/DOMNamedFlowCollection.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/DOMNamedFlowCollection.cpp')
-rw-r--r-- | Source/WebCore/dom/DOMNamedFlowCollection.cpp | 76 |
1 files changed, 42 insertions, 34 deletions
diff --git a/Source/WebCore/dom/DOMNamedFlowCollection.cpp b/Source/WebCore/dom/DOMNamedFlowCollection.cpp index 39b3784bf..cdc1f73fb 100644 --- a/Source/WebCore/dom/DOMNamedFlowCollection.cpp +++ b/Source/WebCore/dom/DOMNamedFlowCollection.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,60 +27,67 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #include "config.h" #include "DOMNamedFlowCollection.h" +#include "WebKitNamedFlow.h" +#include <wtf/text/AtomicStringHash.h> namespace WebCore { -DOMNamedFlowCollection::DOMNamedFlowCollection(const Vector<WebKitNamedFlow*>& namedFlows) +inline DOMNamedFlowCollection::DOMNamedFlowCollection(Vector<Ref<WebKitNamedFlow>>&& flows) + : m_flows(WTFMove(flows)) { - for (Vector<WebKitNamedFlow*>::const_iterator it = namedFlows.begin(); it != namedFlows.end(); ++it) - m_namedFlows.add(*it); } -unsigned long DOMNamedFlowCollection::length() const +Ref<DOMNamedFlowCollection> DOMNamedFlowCollection::create(Vector<Ref<WebKitNamedFlow>>&& flows) { - return m_namedFlows.size(); + return adoptRef(*new DOMNamedFlowCollection(WTFMove(flows))); } -PassRefPtr<WebKitNamedFlow> DOMNamedFlowCollection::item(unsigned long index) const +DOMNamedFlowCollection::~DOMNamedFlowCollection() { - if (index >= static_cast<unsigned long>(m_namedFlows.size())) - return 0; - DOMNamedFlowSet::const_iterator it = m_namedFlows.begin(); - for (unsigned long i = 0; i < index; ++i) - ++it; - return *it; } -PassRefPtr<WebKitNamedFlow> DOMNamedFlowCollection::namedItem(const AtomicString& name) const +WebKitNamedFlow* DOMNamedFlowCollection::item(unsigned index) const { - DOMNamedFlowSet::const_iterator it = m_namedFlows.find<String, DOMNamedFlowHashTranslator>(name); - if (it != m_namedFlows.end()) - return *it; - return 0; + if (index >= m_flows.size()) + return nullptr; + return const_cast<WebKitNamedFlow*>(m_flows[index].ptr()); } -bool DOMNamedFlowCollection::hasNamedItem(const AtomicString& name) const -{ - return namedItem(name); -} +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; -// The HashFunctions object used by the HashSet to compare between RefPtr<NamedFlows>. -// It is safe to set safeToCompareToEmptyOrDeleted because the HashSet will never contain null pointers or deleted values. -struct DOMNamedFlowCollection::DOMNamedFlowHashFunctions { - static unsigned hash(PassRefPtr<WebKitNamedFlow> key) { return DefaultHash<String>::Hash::hash(key->name()); } - static bool equal(PassRefPtr<WebKitNamedFlow> a, PassRefPtr<WebKitNamedFlow> b) { return a->name() == b->name(); } - static const bool safeToCompareToEmptyOrDeleted = true; + static unsigned hash(const AtomicString& key) { return AtomicStringHash::hash(key); } + static bool equal(const WebKitNamedFlow* a, const AtomicString& b) { return a->name() == b; } }; -// The HashTranslator is used to lookup a RefPtr<NamedFlow> in the set using a name. -struct DOMNamedFlowCollection::DOMNamedFlowHashTranslator { - static unsigned hash(const String& key) { return DefaultHash<String>::Hash::hash(key); } - static bool equal(PassRefPtr<WebKitNamedFlow> a, const String& b) { return a->name() == b; } -}; -} // namespace WebCore - +WebKitNamedFlow* DOMNamedFlowCollection::namedItem(const AtomicString& name) const +{ + if (m_flowsByName.isEmpty()) { + // No need to optimize the case where m_flows is empty; will do nothing very quickly. + 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()) { + // No need to optimize the case where m_flows is empty; will do nothing relatively quickly. + m_flowNames.reserveInitialCapacity(m_flows.size()); + for (auto& flow : m_flows) + m_flowNames.uncheckedAppend(flow->name()); + } + return m_flowNames; +} +} // namespace WebCore |