| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012, 2013 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2012, 2013 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/dom/ElementDataCache.h" | 27 #include "core/dom/ElementDataCache.h" |
| 28 | 28 |
| 29 #include "core/dom/ElementData.h" | 29 #include "core/dom/ElementData.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(ElementDataCache) | |
| 34 | |
| 35 inline unsigned attributeHash(const Vector<Attribute>& attributes) | 33 inline unsigned attributeHash(const Vector<Attribute>& attributes) |
| 36 { | 34 { |
| 37 return StringHasher::hashMemory(attributes.data(), attributes.size() * sizeo
f(Attribute)); | 35 return StringHasher::hashMemory(attributes.data(), attributes.size() * sizeo
f(Attribute)); |
| 38 } | 36 } |
| 39 | 37 |
| 40 inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElem
entData& elementData) | 38 inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElem
entData& elementData) |
| 41 { | 39 { |
| 42 if (attributes.size() != elementData.attributes().size()) | 40 if (attributes.size() != elementData.attributes().size()) |
| 43 return false; | 41 return false; |
| 44 return !memcmp(attributes.data(), elementData.m_attributeArray, attributes.s
ize() * sizeof(Attribute)); | 42 return !memcmp(attributes.data(), elementData.m_attributeArray, attributes.s
ize() * sizeof(Attribute)); |
| 45 } | 43 } |
| 46 | 44 |
| 47 PassRefPtrWillBeRawPtr<ShareableElementData> ElementDataCache::cachedShareableEl
ementDataWithAttributes(const Vector<Attribute>& attributes) | 45 RawPtr<ShareableElementData> ElementDataCache::cachedShareableElementDataWithAtt
ributes(const Vector<Attribute>& attributes) |
| 48 { | 46 { |
| 49 ASSERT(!attributes.isEmpty()); | 47 ASSERT(!attributes.isEmpty()); |
| 50 | 48 |
| 51 ShareableElementDataCache::ValueType* it = m_shareableElementDataCache.add(a
ttributeHash(attributes), nullptr).storedValue; | 49 ShareableElementDataCache::ValueType* it = m_shareableElementDataCache.add(a
ttributeHash(attributes), nullptr).storedValue; |
| 52 | 50 |
| 53 // FIXME: This prevents sharing when there's a hash collision. | 51 // FIXME: This prevents sharing when there's a hash collision. |
| 54 if (it->value && !hasSameAttributes(attributes, *it->value)) | 52 if (it->value && !hasSameAttributes(attributes, *it->value)) |
| 55 return ShareableElementData::createWithAttributes(attributes); | 53 return ShareableElementData::createWithAttributes(attributes); |
| 56 | 54 |
| 57 if (!it->value) | 55 if (!it->value) |
| 58 it->value = ShareableElementData::createWithAttributes(attributes); | 56 it->value = ShareableElementData::createWithAttributes(attributes); |
| 59 | 57 |
| 60 return it->value.get(); | 58 return it->value.get(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 ElementDataCache::ElementDataCache() | 61 ElementDataCache::ElementDataCache() |
| 64 { | 62 { |
| 65 } | 63 } |
| 66 | 64 |
| 67 DEFINE_TRACE(ElementDataCache) | 65 DEFINE_TRACE(ElementDataCache) |
| 68 { | 66 { |
| 69 #if ENABLE(OILPAN) | 67 #if ENABLE(OILPAN) |
| 70 visitor->trace(m_shareableElementDataCache); | 68 visitor->trace(m_shareableElementDataCache); |
| 71 #endif | 69 #endif |
| 72 } | 70 } |
| 73 | 71 |
| 74 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |