This source file includes following definitions.
- attributeHash
- hasSameAttributes
- cachedShareableElementDataWithAttributes
#include "config.h"
#include "core/dom/ElementDataCache.h"
#include "core/dom/ElementData.h"
namespace WebCore {
inline unsigned attributeHash(const Vector<Attribute>& attributes)
{
return StringHasher::hashMemory(attributes.data(), attributes.size() * sizeof(Attribute));
}
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> ElementDataCache::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes)
{
ASSERT(!attributes.isEmpty());
ShareableElementDataCache::ValueType* it = m_shareableElementDataCache.add(attributeHash(attributes), nullptr).storedValue;
if (it->value && !hasSameAttributes(attributes, *it->value))
return ShareableElementData::createWithAttributes(attributes);
if (!it->value)
it->value = ShareableElementData::createWithAttributes(attributes);
return it->value.get();
}
ElementDataCache::ElementDataCache()
{
}
ElementDataCache::~ElementDataCache()
{
}
}