diff options
author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-05-30 12:48:17 +0200 |
commit | 881da28418d380042aa95a97f0cbd42560a64f7c (patch) | |
tree | a794dff3274695e99c651902dde93d934ea7a5af /Source/WebCore/dom/DocumentSharedObjectPool.cpp | |
parent | 7e104c57a70fdf551bb3d22a5d637cdcbc69dbea (diff) | |
parent | 0fcedcd17cc00d3dd44c718b3cb36c1033319671 (diff) | |
download | qtwebkit-881da28418d380042aa95a97f0cbd42560a64f7c.tar.gz |
Merge 'wip/next' into dev
Change-Id: Iff9ee5e23bb326c4371ec8ed81d56f2f05d680e9
Diffstat (limited to 'Source/WebCore/dom/DocumentSharedObjectPool.cpp')
-rw-r--r-- | Source/WebCore/dom/DocumentSharedObjectPool.cpp | 80 |
1 files changed, 20 insertions, 60 deletions
diff --git a/Source/WebCore/dom/DocumentSharedObjectPool.cpp b/Source/WebCore/dom/DocumentSharedObjectPool.cpp index 997e8668d..b5f721cae 100644 --- a/Source/WebCore/dom/DocumentSharedObjectPool.cpp +++ b/Source/WebCore/dom/DocumentSharedObjectPool.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -31,72 +31,32 @@ namespace WebCore { -class ShareableElementDataCacheKey { -public: - ShareableElementDataCacheKey(const Attribute* attributes, unsigned attributeCount) - : m_attributes(attributes) - , m_attributeCount(attributeCount) - { } - - bool operator!=(const ShareableElementDataCacheKey& other) const - { - if (m_attributeCount != other.m_attributeCount) - return true; - return memcmp(m_attributes, other.m_attributes, sizeof(Attribute) * m_attributeCount); - } - - unsigned hash() const - { - return StringHasher::hashMemory(m_attributes, m_attributeCount * sizeof(Attribute)); - } - -private: - const Attribute* m_attributes; - unsigned m_attributeCount; -}; - -class ShareableElementDataCacheEntry { -public: - ShareableElementDataCacheEntry(const ShareableElementDataCacheKey& k, PassRefPtr<ShareableElementData> v) - : key(k) - , value(v) - { } +inline unsigned attributeHash(const Vector<Attribute>& attributes) +{ + return StringHasher::hashMemory(attributes.data(), attributes.size() * sizeof(Attribute)); +} - ShareableElementDataCacheKey key; - RefPtr<ShareableElementData> value; -}; +inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElementData& elementData) +{ + if (attributes.size() != elementData.length()) + return false; + return !memcmp(attributes.data(), elementData.m_attributeArray, attributes.size() * sizeof(Attribute)); +} -PassRefPtr<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes) +Ref<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes) { ASSERT(!attributes.isEmpty()); - ShareableElementDataCacheKey cacheKey(attributes.data(), attributes.size()); - unsigned cacheHash = cacheKey.hash(); + auto& cachedData = m_shareableElementDataCache.add(attributeHash(attributes), nullptr).iterator->value; - ShareableElementDataCache::iterator cacheIterator = m_shareableElementDataCache.add(cacheHash, nullptr).iterator; - if (cacheIterator->value && cacheIterator->value->key != cacheKey) - cacheHash = 0; + // FIXME: This prevents sharing when there's a hash collision. + if (cachedData && !hasSameAttributes(attributes, *cachedData)) + return ShareableElementData::createWithAttributes(attributes); - RefPtr<ShareableElementData> elementData; - if (cacheHash && cacheIterator->value) - elementData = cacheIterator->value->value; - else - elementData = ShareableElementData::createWithAttributes(attributes); + if (!cachedData) + cachedData = ShareableElementData::createWithAttributes(attributes); - if (!cacheHash || cacheIterator->value) - return elementData.release(); - - cacheIterator->value = adoptPtr(new ShareableElementDataCacheEntry(ShareableElementDataCacheKey(elementData->m_attributeArray, elementData->length()), elementData)); - - return elementData.release(); -} - -DocumentSharedObjectPool::DocumentSharedObjectPool() -{ -} - -DocumentSharedObjectPool::~DocumentSharedObjectPool() -{ + return *cachedData; } } |