Commit 43fbe49f authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Rename ElementData's attribute related methods for clarity

Rename ElementData's attribute related methods for clarity:
* length() -> attributeCount()
* isEmpty() -> hasAttributes()
* getAttributeItem(name) -> findAttributeByName(name)
* attributeItem(index) -> attributeAt(index)
* getAttributeItemIndex(name) -> findAttributeIndexByName(name)
* addAttribute(name, value) -> appendAttribute(name, value)
* removeAttribute(index) -> removeAttributeAt(index)

This is inpired by the following WebKit revision by benjamin@webkit.org:
http://trac.webkit.org/changeset/162394

R=esprehn@chromium.org, adamk@chromium.org

Review URL: https://codereview.chromium.org/313973003

git-svn-id: svn://svn.chromium.org/blink/trunk@175611 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ae86fc7d
......@@ -202,7 +202,7 @@ Attribute& Attr::elementAttribute()
{
ASSERT(m_element);
ASSERT(m_element->elementData());
return *m_element->ensureUniqueElementData().getAttributeItem(qualifiedName());
return *m_element->ensureUniqueElementData().findAttributeByName(qualifiedName());
}
void Attr::detachFromElementWithValue(const AtomicString& value)
......
......@@ -171,10 +171,10 @@ public:
// performance.
AttributeIteratorAccessor attributesIterator() const { return elementData()->attributesIterator(); }
size_t attributeCount() const;
const Attribute& attributeItem(unsigned index) const;
const Attribute* getAttributeItem(const QualifiedName&) const;
size_t getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); }
size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
const Attribute& attributeAt(unsigned index) const;
const Attribute* findAttributeByName(const QualifiedName&) const;
size_t findAttributeIndexByName(const QualifiedName& name) const { return elementData()->findAttributeIndexByName(name); }
size_t findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
void scrollIntoView(bool alignToTop = true);
void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
......@@ -602,7 +602,7 @@ private:
virtual bool childTypeAllowed(NodeType) const OVERRIDE FINAL;
void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
void appendAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
void attributeChangedFromParserOrByCloning(const QualifiedName&, const AtomicString&, AttributeModificationReason);
......@@ -695,14 +695,14 @@ inline Element* Node::parentElement() const
inline bool Element::fastHasAttribute(const QualifiedName& name) const
{
ASSERT(fastAttributeLookupAllowed(name));
return elementData() && getAttributeItem(name);
return elementData() && findAttributeByName(name);
}
inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
{
ASSERT(fastAttributeLookupAllowed(name));
if (elementData()) {
if (const Attribute* attribute = getAttributeItem(name))
if (const Attribute* attribute = findAttributeByName(name))
return attribute->value();
}
return nullAtom;
......@@ -710,7 +710,7 @@ inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name)
inline bool Element::hasAttributesWithoutUpdate() const
{
return elementData() && !elementData()->isEmpty();
return elementData() && elementData()->hasAttributes();
}
inline const AtomicString& Element::idForStyleResolution() const
......@@ -767,19 +767,19 @@ inline const SpaceSplitString& Element::classNames() const
inline size_t Element::attributeCount() const
{
ASSERT(elementData());
return elementData()->length();
return elementData()->attributeCount();
}
inline const Attribute& Element::attributeItem(unsigned index) const
inline const Attribute& Element::attributeAt(unsigned index) const
{
ASSERT(elementData());
return elementData()->attributeItem(index);
return elementData()->attributeAt(index);
}
inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const
inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const
{
ASSERT(elementData());
return elementData()->getAttributeItem(name);
return elementData()->findAttributeByName(name);
}
inline bool Element::hasID() const
......
......@@ -70,7 +70,7 @@ ElementData::ElementData(unsigned arraySize)
ElementData::ElementData(const ElementData& other, bool isUnique)
: m_isUnique(isUnique)
, m_arraySize(isUnique ? 0 : other.length())
, m_arraySize(isUnique ? 0 : other.attributeCount())
, m_presentationAttributeStyleIsDirty(other.m_presentationAttributeStyleIsDirty)
, m_styleAttributeIsDirty(other.m_styleAttributeIsDirty)
, m_animatedSVGAttributesAreDirty(other.m_animatedSVGAttributesAreDirty)
......@@ -98,22 +98,22 @@ PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const
bool ElementData::isEquivalent(const ElementData* other) const
{
if (!other)
return isEmpty();
return !hasAttributes();
AttributeIteratorAccessor attributes = attributesIterator();
if (attributes.size() != other->length())
if (attributes.size() != other->attributeCount())
return false;
AttributeConstIterator end = attributes.end();
for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
const Attribute* otherAttr = other->getAttributeItem(it->name());
const Attribute* otherAttr = other->findAttributeByName(it->name());
if (!otherAttr || it->value() != otherAttr->value())
return false;
}
return true;
}
size_t ElementData::getAttrIndex(Attr* attr) const
size_t ElementData::findAttrNodeIndex(Attr* attr) const
{
// This relies on the fact that Attr's QualifiedName == the Attribute's name.
AttributeIteratorAccessor attributes = attributesIterator();
......@@ -125,7 +125,7 @@ size_t ElementData::getAttrIndex(Attr* attr) const
return kNotFound;
}
size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const
size_t ElementData::findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const
{
// Continue to checking case-insensitively and/or full namespaced names if necessary:
AttributeIteratorAccessor attributes = attributesIterator();
......@@ -198,7 +198,7 @@ UniqueElementData::UniqueElementData(const ShareableElementData& other)
ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable());
m_inlineStyle = other.m_inlineStyle;
unsigned length = other.length();
unsigned length = other.attributeCount();
m_attributeVector.reserveCapacity(length);
for (unsigned i = 0; i < length; ++i)
m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
......@@ -215,7 +215,7 @@ PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const
return adoptRef(new (slot) ShareableElementData(*this));
}
Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name)
Attribute* UniqueElementData::findAttributeByName(const QualifiedName& name)
{
unsigned length = m_attributeVector.size();
for (unsigned i = 0; i < length; ++i) {
......
......@@ -102,16 +102,16 @@ public:
const StylePropertySet* presentationAttributeStyle() const;
// This is not a trivial getter and its return value should be cached for performance.
size_t length() const;
bool isEmpty() const { return !length(); }
size_t attributeCount() const;
bool hasAttributes() const { return !!attributeCount(); }
AttributeIteratorAccessor attributesIterator() const;
const Attribute& attributeItem(unsigned index) const;
const Attribute* getAttributeItem(const QualifiedName&) const;
size_t getAttributeItemIndex(const QualifiedName&, bool shouldIgnoreCase = false) const;
size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
size_t getAttrIndex(Attr*) const;
const Attribute& attributeAt(unsigned index) const;
const Attribute* findAttributeByName(const QualifiedName&) const;
size_t findAttributeIndexByName(const QualifiedName&, bool shouldIgnoreCase = false) const;
size_t findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
size_t findAttrNodeIndex(Attr*) const;
bool hasID() const { return !m_idForStyleResolution.isNull(); }
bool hasClass() const { return !m_classNames.isNull(); }
......@@ -145,8 +145,8 @@ private:
void destroy();
const Attribute* attributeBase() const;
const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
const Attribute* findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
size_t findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
PassRefPtr<UniqueElementData> makeUniqueCopy() const;
};
......@@ -187,11 +187,11 @@ public:
PassRefPtr<ShareableElementData> makeShareableCopy() const;
// These functions do no error/duplicate checking.
void addAttribute(const QualifiedName&, const AtomicString&);
void removeAttribute(size_t index);
void appendAttribute(const QualifiedName&, const AtomicString&);
void removeAttributeAt(size_t index);
Attribute& attributeItem(unsigned index);
Attribute* getAttributeItem(const QualifiedName&);
Attribute& attributeAt(unsigned index);
Attribute* findAttributeByName(const QualifiedName&);
UniqueElementData();
explicit UniqueElementData(const ShareableElementData&);
......@@ -212,7 +212,7 @@ inline void ElementData::deref()
destroy();
}
inline size_t ElementData::length() const
inline size_t ElementData::attributeCount() const
{
if (isUnique())
return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
......@@ -226,11 +226,11 @@ inline const StylePropertySet* ElementData::presentationAttributeStyle() const
return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();
}
inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
inline const Attribute* ElementData::findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const
{
size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
size_t index = findAttributeIndexByName(name, shouldIgnoreAttributeCase);
if (index != kNotFound)
return &attributeItem(index);
return &attributeAt(index);
return 0;
}
......@@ -241,7 +241,7 @@ inline const Attribute* ElementData::attributeBase() const
return static_cast<const ShareableElementData*>(this)->m_attributeArray;
}
inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool shouldIgnoreCase) const
inline size_t ElementData::findAttributeIndexByName(const QualifiedName& name, bool shouldIgnoreCase) const
{
AttributeIteratorAccessor attributes = attributesIterator();
AttributeConstIterator end = attributes.end();
......@@ -254,7 +254,7 @@ inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool
// We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller
// can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
inline size_t ElementData::findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const
{
bool doSlowCheck = shouldIgnoreAttributeCase;
......@@ -273,7 +273,7 @@ inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool
}
if (doSlowCheck)
return getAttributeItemIndexSlowCase(name, shouldIgnoreAttributeCase);
return findAttributeIndexByNameSlowCase(name, shouldIgnoreAttributeCase);
return kNotFound;
}
......@@ -286,7 +286,7 @@ inline AttributeIteratorAccessor ElementData::attributesIterator() const
return AttributeIteratorAccessor(static_cast<const ShareableElementData*>(this)->m_attributeArray, m_arraySize);
}
inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const
inline const Attribute* ElementData::findAttributeByName(const QualifiedName& name) const
{
AttributeIteratorAccessor attributes = attributesIterator();
AttributeConstIterator end = attributes.end();
......@@ -297,24 +297,24 @@ inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name)
return 0;
}
inline const Attribute& ElementData::attributeItem(unsigned index) const
inline const Attribute& ElementData::attributeAt(unsigned index) const
{
RELEASE_ASSERT(index < length());
RELEASE_ASSERT(index < attributeCount());
ASSERT(attributeBase() + index);
return *(attributeBase() + index);
}
inline void UniqueElementData::addAttribute(const QualifiedName& attributeName, const AtomicString& value)
inline void UniqueElementData::appendAttribute(const QualifiedName& attributeName, const AtomicString& value)
{
m_attributeVector.append(Attribute(attributeName, value));
}
inline void UniqueElementData::removeAttribute(size_t index)
inline void UniqueElementData::removeAttributeAt(size_t index)
{
m_attributeVector.remove(index);
}
inline Attribute& UniqueElementData::attributeItem(unsigned index)
inline Attribute& UniqueElementData::attributeAt(unsigned index)
{
return m_attributeVector.at(index);
}
......
......@@ -38,7 +38,7 @@ inline unsigned attributeHash(const Vector<Attribute>& attributes)
inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElementData& elementData)
{
if (attributes.size() != elementData.length())
if (attributes.size() != elementData.attributeCount())
return false;
return !memcmp(attributes.data(), elementData.m_attributeArray, attributes.size() * sizeof(Attribute));
}
......
......@@ -59,7 +59,7 @@ PassRefPtrWillBeRawPtr<Node> NamedNodeMap::getNamedItemNS(const AtomicString& na
PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionState& exceptionState)
{
size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(name, m_element->shouldIgnoreAttributeCase()) : kNotFound;
size_t index = m_element->hasAttributes() ? m_element->findAttributeIndexByName(name, m_element->shouldIgnoreAttributeCase()) : kNotFound;
if (index == kNotFound) {
exceptionState.throwDOMException(NotFoundError, "No item with name '" + name + "' was found.");
return nullptr;
......@@ -69,7 +69,7 @@ PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& n
PassRefPtrWillBeRawPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionState& exceptionState)
{
size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(QualifiedName(nullAtom, localName, namespaceURI)) : kNotFound;
size_t index = m_element->hasAttributes() ? m_element->findAttributeIndexByName(QualifiedName(nullAtom, localName, namespaceURI)) : kNotFound;
if (index == kNotFound) {
exceptionState.throwDOMException(NotFoundError, "No item with name '" + namespaceURI + "::" + localName + "' was found.");
return nullptr;
......@@ -102,7 +102,7 @@ PassRefPtrWillBeRawPtr<Node> NamedNodeMap::item(unsigned index) const
{
if (index >= length())
return nullptr;
return m_element->ensureAttr(m_element->attributeItem(index).name());
return m_element->ensureAttr(m_element->attributeAt(index).name());
}
size_t NamedNodeMap::length() const
......
......@@ -452,11 +452,11 @@ void HTMLInputElement::updateType()
if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttributes()) {
ASSERT(elementData());
if (const Attribute* height = getAttributeItem(heightAttr))
if (const Attribute* height = findAttributeByName(heightAttr))
attributeChanged(heightAttr, height->value());
if (const Attribute* width = getAttributeItem(widthAttr))
if (const Attribute* width = findAttributeByName(widthAttr))
attributeChanged(widthAttr, width->value());
if (const Attribute* align = getAttributeItem(alignAttr))
if (const Attribute* align = findAttributeByName(alignAttr))
attributeChanged(alignAttr, align->value());
}
......
......@@ -323,7 +323,7 @@ void HTMLSelectElement::parseAttribute(const QualifiedName& name, const AtomicSt
AtomicString attrSize = AtomicString::number(size);
if (attrSize != value) {
// FIXME: This is horribly factored.
if (Attribute* sizeAttribute = ensureUniqueElementData().getAttributeItem(sizeAttr))
if (Attribute* sizeAttribute = ensureUniqueElementData().findAttributeByName(sizeAttr))
sizeAttribute->setValue(attrSize);
}
size = max(size, 1);
......
......@@ -407,7 +407,7 @@ void HTMLConstructionSite::mergeAttributesFromTokenIntoElement(AtomicHTMLToken*
for (unsigned i = 0; i < token->attributes().size(); ++i) {
const Attribute& tokenAttribute = token->attributes().at(i);
if (!element->elementData() || !element->getAttributeItem(tokenAttribute.name()))
if (!element->elementData() || !element->findAttributeByName(tokenAttribute.name()))
element->setAttribute(tokenAttribute.name(), tokenAttribute.value());
}
}
......
......@@ -191,7 +191,7 @@ bool DOMPatchSupport::innerPatchNode(Digest* oldDigest, Digest* newDigest, Excep
// FIXME: Create a function in Element for removing all properties. Take in account whether did/willModifyAttribute are important.
if (oldElement->hasAttributesWithoutUpdate()) {
while (oldElement->attributeCount()) {
const Attribute& attribute = oldElement->attributeItem(0);
const Attribute& attribute = oldElement->attributeAt(0);
if (!m_domEditor->removeAttribute(oldElement, attribute.localName(), exceptionState))
return false;
}
......
......@@ -603,7 +603,7 @@ Value FunLang::evaluate() const
if (node->isElementNode()) {
Element* element = toElement(node);
if (element->hasAttributes())
languageAttribute = element->getAttributeItem(XMLNames::langAttr);
languageAttribute = element->findAttributeByName(XMLNames::langAttr);
}
if (languageAttribute)
break;
......
......@@ -126,14 +126,14 @@ WebString WebElement::attributeLocalName(unsigned index) const
{
if (index >= attributeCount())
return WebString();
return constUnwrap<Element>()->attributeItem(index).localName();
return constUnwrap<Element>()->attributeAt(index).localName();
}
WebString WebElement::attributeValue(unsigned index) const
{
if (index >= attributeCount())
return WebString();
return constUnwrap<Element>()->attributeItem(index).value();
return constUnwrap<Element>()->attributeAt(index).value();
}
WebString WebElement::innerText()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment