Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parserSetAttributes() to take in a Span instead of a Vector #10178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Source/WebCore/dom/DocumentSharedObjectPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ ALWAYS_INLINE bool equalAttributes(const uint8_t* a, const uint8_t* b, unsigned
}
#endif

inline bool hasSameAttributes(const Vector<Attribute>& attributes, ShareableElementData& elementData)
inline bool hasSameAttributes(Span<const Attribute> attributes, ShareableElementData& elementData)
{
if (attributes.size() != elementData.length())
return false;
return equalAttributes(reinterpret_cast<const uint8_t*>(attributes.data()), reinterpret_cast<const uint8_t*>(elementData.m_attributeArray), attributes.size() * sizeof(Attribute));
}

Ref<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes)
Ref<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(Span<const Attribute> attributes)
{
ASSERT(!attributes.isEmpty());
ASSERT(!attributes.empty());

auto& cachedData = m_shareableElementDataCache.add(computeHash(attributes), nullptr).iterator->value;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/DocumentSharedObjectPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ShareableElementData;
class DocumentSharedObjectPool {
WTF_MAKE_FAST_ALLOCATED;
public:
Ref<ShareableElementData> cachedShareableElementDataWithAttributes(const Vector<Attribute>&);
Ref<ShareableElementData> cachedShareableElementDataWithAttributes(Span<const Attribute>);

private:
typedef HashMap<unsigned, RefPtr<ShareableElementData>, AlreadyHashed> ShareableElementDataCache;
Expand Down
12 changes: 6 additions & 6 deletions Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,24 +2464,24 @@ void Element::stripScriptingAttributes(Vector<Attribute>& attributeVector) const
});
}

void Element::parserSetAttributes(const Vector<Attribute>& attributeVector)
void Element::parserSetAttributes(Span<const Attribute> attributes)
{
ASSERT(!isConnected());
ASSERT(!parentNode());
ASSERT(!m_elementData);

if (!attributeVector.isEmpty()) {
if (attributes.size()) {
if (document().sharedObjectPool())
m_elementData = document().sharedObjectPool()->cachedShareableElementDataWithAttributes(attributeVector);
m_elementData = document().sharedObjectPool()->cachedShareableElementDataWithAttributes(attributes);
else
m_elementData = ShareableElementData::createWithAttributes(attributeVector);
m_elementData = ShareableElementData::createWithAttributes(attributes);

}

parserDidSetAttributes();

// Use attributeVector instead of m_elementData because attributeChanged might modify m_elementData.
for (const auto& attribute : attributeVector)
// Use attributes instead of m_elementData because attributeChanged might modify m_elementData.
for (const auto& attribute : attributes)
attributeChanged(attribute.name(), nullAtom(), attribute.value(), ModifiedDirectly);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class Element : public ContainerNode {
virtual void parseAttribute(const QualifiedName&, const AtomString&) { }

// Only called by the parser immediately after element construction.
void parserSetAttributes(const Vector<Attribute>&);
void parserSetAttributes(Span<const Attribute>);

bool isEventHandlerAttribute(const Attribute&) const;
virtual FormListedElement* asFormListedElement();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/dom/ElementData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
return sizeof(ShareableElementData) + sizeof(Attribute) * count;
}

Ref<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
Ref<ShareableElementData> ShareableElementData::createWithAttributes(Span<const Attribute> attributes)
{
void* slot = ShareableElementDataMalloc::malloc(sizeForShareableElementDataWithAttributeCount(attributes.size()));
return adoptRef(*new (NotNull, slot) ShareableElementData(attributes));
Expand All @@ -81,7 +81,7 @@ Ref<UniqueElementData> UniqueElementData::create()
return adoptRef(*new UniqueElementData);
}

ShareableElementData::ShareableElementData(const Vector<Attribute>& attributes)
ShareableElementData::ShareableElementData(Span<const Attribute> attributes)
: ElementData(attributes.size())
{
unsigned attributeArraySize = arraySize();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/dom/ElementData.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ShareableElementData);
class ShareableElementData : public ElementData {
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(ShareableElementData);
public:
static Ref<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
static Ref<ShareableElementData> createWithAttributes(Span<const Attribute>);

explicit ShareableElementData(const Vector<Attribute>&);
explicit ShareableElementData(Span<const Attribute>);
explicit ShareableElementData(const UniqueElementData&);
~ShareableElementData();

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/parser/HTMLConstructionSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static inline void setAttributes(Element& element, Vector<Attribute>& attributes
{
if (!scriptingContentIsAllowed(parserContentPolicy))
element.stripScriptingAttributes(attributes);
element.parserSetAttributes(attributes);
element.parserSetAttributes(attributes.span());
element.setHasDuplicateAttribute(hasDuplicateAttribute == HasDuplicateAttribute::Yes);
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/shadow/TextControlInnerElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ void TextControlInnerTextElement::updateInnerTextElementEditabilityImpl(bool isE
{
const auto& value = isEditable ? plaintextOnlyAtom() : falseAtom();
if (initialization) {
Vector<Attribute> attributes { Attribute(contenteditableAttr, value) };
parserSetAttributes(attributes);
Attribute attribute(contenteditableAttr, value);
parserSetAttributes(Span { &attribute, 1 });
} else
setAttributeWithoutSynchronization(contenteditableAttr, value);
}
Expand Down
15 changes: 6 additions & 9 deletions Source/WebCore/xml/XMLErrors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,16 @@ static inline Ref<Element> createXHTMLParserErrorHeader(Document& document, Stri
{
Ref<Element> reportElement = document.createElement(QualifiedName(nullAtom(), "parsererror"_s, xhtmlNamespaceURI), true);

Vector<Attribute> reportAttributes;
reportAttributes.append(Attribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"_s));
reportElement->parserSetAttributes(reportAttributes);
Attribute reportAttribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"_s);
reportElement->parserSetAttributes(Span { &reportAttribute, 1 });

auto h3 = HTMLHeadingElement::create(h3Tag, document);
reportElement->parserAppendChild(h3);
h3->parserAppendChild(Text::create(document, "This page contains the following errors:"_s));

auto fixed = HTMLDivElement::create(document);
Vector<Attribute> fixedAttributes;
fixedAttributes.append(Attribute(styleAttr, "font-family:monospace;font-size:12px"_s));
fixed->parserSetAttributes(fixedAttributes);
Attribute fixedAttribute(styleAttr, "font-family:monospace;font-size:12px"_s);
fixed->parserSetAttributes(Span { &fixedAttribute, 1 });
reportElement->parserAppendChild(fixed);

fixed->parserAppendChild(Text::create(document, WTFMove(errorMessages)));
Expand Down Expand Up @@ -146,10 +144,9 @@ void XMLErrors::insertErrorMessageBlock()

#if ENABLE(XSLT)
if (m_document.transformSourceDocument()) {
Vector<Attribute> attributes;
attributes.append(Attribute(styleAttr, "white-space: normal"_s));
Attribute attribute(styleAttr, "white-space: normal"_s);
auto paragraph = HTMLParagraphElement::create(m_document);
paragraph->parserSetAttributes(attributes);
paragraph->parserSetAttributes(Span { &attribute, 1 });
paragraph->parserAppendChild(m_document.createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."_s));
reportElement->parserAppendChild(paragraph);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ static inline void setAttributes(Element* element, Vector<Attribute>& attributeV
{
if (!scriptingContentIsAllowed(parserContentPolicy))
element->stripScriptingAttributes(attributeVector);
element->parserSetAttributes(attributeVector);
element->parserSetAttributes(attributeVector.span());
}

static void switchToUTF16(xmlParserCtxtPtr ctxt)
Expand Down