From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- .../svg/properties/SVGAttributeToPropertyMap.cpp | 116 +++++++-------------- 1 file changed, 36 insertions(+), 80 deletions(-) (limited to 'Source/WebCore/svg/properties/SVGAttributeToPropertyMap.cpp') 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(); - 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>& properties) +Vector> 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> 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& propertyTypes) +Vector 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 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 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 -- cgit v1.2.1