diff options
Diffstat (limited to 'Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp')
-rw-r--r-- | Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp | 116 |
1 files changed, 36 insertions, 80 deletions
diff --git a/Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp b/Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp index 2c3949bed..9629e58ca 100644 --- a/Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp +++ b/Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) Research In Motion Limited 2011. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,113 +19,68 @@ */ #include "config.h" - -#if ENABLE(SVG) #include "SVGAttributeToPropertyMap.h" #include "SVGAnimatedProperty.h" -#include "SVGPropertyInfo.h" namespace WebCore { void SVGAttributeToPropertyMap::addProperties(const SVGAttributeToPropertyMap& map) { - AttributeToPropertiesMap::const_iterator end = map.m_map.end(); - for (AttributeToPropertiesMap::const_iterator it = map.m_map.begin(); it != end; ++it) { - const PropertiesVector* vector = it->value.get(); - ASSERT(vector); - - // FIXME: This looks up the attribute name in the hash table for each property, even though all the - // properties in a single vector are guaranteed to have the same attribute name. - // FIXME: This grows the vector one item at a time, even though we know up front exactly how many - // elements we are adding to the vector. - PropertiesVector::const_iterator vectorEnd = vector->end(); - for (PropertiesVector::const_iterator vectorIt = vector->begin(); vectorIt != vectorEnd; ++vectorIt) - addProperty(*vectorIt); + for (auto& vector : map.m_map.values()) { + ASSERT(!vector.isEmpty()); + auto& properties = m_map.add(vector[0]->attributeName, PropertyInfoVector()).iterator->value; + properties.reserveCapacity(properties.size() + vector.size()); + for (auto* property : vector) + properties.uncheckedAppend(property); } } -void SVGAttributeToPropertyMap::addProperty(const SVGPropertyInfo* info) +void SVGAttributeToPropertyMap::addProperty(const SVGPropertyInfo& info) { - ASSERT(info); - ASSERT(info->attributeName != anyQName()); - if (PropertiesVector* vector = m_map.get(info->attributeName)) { - vector->append(info); - return; - } - // FIXME: This does a second hash table lookup, but with HashMap::add we could instead do only one. - auto vector = std::make_unique<PropertiesVector>(); - vector->append(info); - m_map.set(info->attributeName, std::move(vector)); + m_map.add(info.attributeName, PropertyInfoVector()).iterator->value.append(&info); } -void SVGAttributeToPropertyMap::animatedPropertiesForAttribute(SVGElement* ownerType, const QualifiedName& attributeName, Vector<RefPtr<SVGAnimatedProperty>>& properties) +Vector<RefPtr<SVGAnimatedProperty>> SVGAttributeToPropertyMap::properties(SVGElement& contextElement, const QualifiedName& attributeName) const { - ASSERT(ownerType); - PropertiesVector* vector = m_map.get(attributeName); - if (!vector) - return; - - PropertiesVector::iterator vectorEnd = vector->end(); - for (PropertiesVector::iterator vectorIt = vector->begin(); vectorIt != vectorEnd; ++vectorIt) - properties.append(animatedProperty(ownerType, attributeName, *vectorIt)); + Vector<RefPtr<SVGAnimatedProperty>> properties; + auto it = m_map.find(attributeName); + if (it == m_map.end()) + return properties; + properties.reserveInitialCapacity(it->value.size()); + for (auto* property : it->value) + properties.uncheckedAppend(property->lookupOrCreateWrapperForAnimatedProperty(&contextElement)); + return properties; } -void SVGAttributeToPropertyMap::animatedPropertyTypeForAttribute(const QualifiedName& attributeName, Vector<AnimatedPropertyType>& propertyTypes) +Vector<AnimatedPropertyType> SVGAttributeToPropertyMap::types(const QualifiedName& attributeName) const { - PropertiesVector* vector = m_map.get(attributeName); - if (!vector) - return; - - PropertiesVector::iterator vectorEnd = vector->end(); - for (PropertiesVector::iterator vectorIt = vector->begin(); vectorIt != vectorEnd; ++vectorIt) - propertyTypes.append((*vectorIt)->animatedPropertyType); + Vector<AnimatedPropertyType> types; + auto it = m_map.find(attributeName); + if (it == m_map.end()) + return types; + types.reserveInitialCapacity(it->value.size()); + for (auto* property : it->value) + types.uncheckedAppend(property->animatedPropertyType); + return types; } -void SVGAttributeToPropertyMap::synchronizeProperties(SVGElement* contextElement) +void SVGAttributeToPropertyMap::synchronizeProperties(SVGElement& contextElement) const { - ASSERT(contextElement); - AttributeToPropertiesMap::iterator end = m_map.end(); - for (AttributeToPropertiesMap::iterator it = m_map.begin(); it != end; ++it) { - PropertiesVector* vector = it->value.get(); - ASSERT(vector); - - PropertiesVector::iterator vectorEnd = vector->end(); - for (PropertiesVector::iterator vectorIt = vector->begin(); vectorIt != vectorEnd; ++vectorIt) - synchronizeProperty(contextElement, it->key, *vectorIt); + for (auto& vector : m_map.values()) { + for (auto* property : vector) + property->synchronizeProperty(&contextElement); } } -bool SVGAttributeToPropertyMap::synchronizeProperty(SVGElement* contextElement, const QualifiedName& attributeName) +bool SVGAttributeToPropertyMap::synchronizeProperty(SVGElement& contextElement, const QualifiedName& attributeName) const { - ASSERT(contextElement); - PropertiesVector* vector = m_map.get(attributeName); - if (!vector) + auto it = m_map.find(attributeName); + if (it == m_map.end()) return false; - - PropertiesVector::iterator vectorEnd = vector->end(); - for (PropertiesVector::iterator vectorIt = vector->begin(); vectorIt != vectorEnd; ++vectorIt) - synchronizeProperty(contextElement, attributeName, *vectorIt); - + for (auto* property : it->value) + property->synchronizeProperty(&contextElement); return true; } -void SVGAttributeToPropertyMap::synchronizeProperty(SVGElement* contextElement, const QualifiedName& attributeName, const SVGPropertyInfo* info) -{ - ASSERT(info); - ASSERT_UNUSED(attributeName, attributeName == info->attributeName); - ASSERT(info->synchronizeProperty); - (*info->synchronizeProperty)(contextElement); -} - -PassRefPtr<SVGAnimatedProperty> SVGAttributeToPropertyMap::animatedProperty(SVGElement* contextElement, const QualifiedName& attributeName, const SVGPropertyInfo* info) -{ - ASSERT(info); - ASSERT_UNUSED(attributeName, attributeName == info->attributeName); - ASSERT(info->lookupOrCreateWrapperForAnimatedProperty); - return (*info->lookupOrCreateWrapperForAnimatedProperty)(contextElement); } - -} - -#endif |