Title: [204721] trunk/Source/WebCore
- Revision
- 204721
- Author
- [email protected]
- Date
- 2016-08-22 09:18:09 -0700 (Mon, 22 Aug 2016)
Log Message
Use memoize pattern for the menclose notation attribute
https://bugs.webkit.org/show_bug.cgi?id=160461
Patch by Frederic Wang <[email protected]> on 2016-08-22
Reviewed by Darin Adler.
Currently, MathMLMencloseElement::parseAttribute parse the "notation" attribute each time it
is changed. We change this to use the memoize pattern as done for other MathML attributes:
We store m_notationFlags in an Optional<uint16_t> where Optnull means that the
attribute is dirty and must be parsed again.
No new tests, already covered by existing tests.
* mathml/MathMLMencloseElement.cpp:
(WebCore::MathMLMencloseElement::parseNotationAttribute): Move parsing of the "notation"
attribute from parseAttribute into this separate helper function.
(WebCore::MathMLMencloseElement::hasNotation): This now check whether the attribute and
dirty and parse it if necessary.
(WebCore::MathMLMencloseElement::parseAttribute): Just make the attribute dirty rather than
parsing it immediately.
* mathml/MathMLMencloseElement.h: hasNotation is no longer const as it may update the
m_notationsFlags. We declare parseNotationAttribute(). Finally, we wrap m_notationFlags
in an Optional<uint16_t> and make addNotation extract the value.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (204720 => 204721)
--- trunk/Source/WebCore/ChangeLog 2016-08-22 16:13:28 UTC (rev 204720)
+++ trunk/Source/WebCore/ChangeLog 2016-08-22 16:18:09 UTC (rev 204721)
@@ -1,3 +1,28 @@
+2016-08-22 Frederic Wang <[email protected]>
+
+ Use memoize pattern for the menclose notation attribute
+ https://bugs.webkit.org/show_bug.cgi?id=160461
+
+ Reviewed by Darin Adler.
+
+ Currently, MathMLMencloseElement::parseAttribute parse the "notation" attribute each time it
+ is changed. We change this to use the memoize pattern as done for other MathML attributes:
+ We store m_notationFlags in an Optional<uint16_t> where Optnull means that the
+ attribute is dirty and must be parsed again.
+
+ No new tests, already covered by existing tests.
+
+ * mathml/MathMLMencloseElement.cpp:
+ (WebCore::MathMLMencloseElement::parseNotationAttribute): Move parsing of the "notation"
+ attribute from parseAttribute into this separate helper function.
+ (WebCore::MathMLMencloseElement::hasNotation): This now check whether the attribute and
+ dirty and parse it if necessary.
+ (WebCore::MathMLMencloseElement::parseAttribute): Just make the attribute dirty rather than
+ parsing it immediately.
+ * mathml/MathMLMencloseElement.h: hasNotation is no longer const as it may update the
+ m_notationsFlags. We declare parseNotationAttribute(). Finally, we wrap m_notationFlags
+ in an Optional<uint16_t> and make addNotation extract the value.
+
2016-08-22 Daniel Bates <[email protected]>
[iOS] <a ping> and <area ping> tests time out
Modified: trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp (204720 => 204721)
--- trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp 2016-08-22 16:13:28 UTC (rev 204720)
+++ trunk/Source/WebCore/mathml/MathMLMencloseElement.cpp 2016-08-22 16:18:09 UTC (rev 204721)
@@ -34,6 +34,8 @@
namespace WebCore {
+using namespace MathMLNames;
+
MathMLMencloseElement::MathMLMencloseElement(const QualifiedName& tagName, Document& document)
: MathMLInlineContainerElement(tagName, document)
{
@@ -52,59 +54,70 @@
return createRenderer<RenderMathMLMenclose>(*this, WTFMove(style));
}
-void MathMLMencloseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
+void MathMLMencloseElement::parseNotationAttribute()
{
- if (name == MathMLNames::notationAttr) {
- clearNotations();
- if (!hasAttribute(name)) {
- addNotation(LongDiv); // default value is longdiv
- return;
- }
- Vector<String> notationsList;
- String(value).split(' ', notationsList);
- for (auto& notation : notationsList) {
- if (notation == "longdiv") {
- addNotation(LongDiv);
- } else if (notation == "roundedbox") {
- addNotation(RoundedBox);
- } else if (notation == "circle") {
- addNotation(Circle);
- } else if (notation == "left") {
- addNotation(Left);
- } else if (notation == "right") {
- addNotation(Right);
- } else if (notation == "top") {
- addNotation(Top);
- } else if (notation == "bottom") {
- addNotation(Bottom);
- } else if (notation == "updiagonalstrike") {
- addNotation(UpDiagonalStrike);
- } else if (notation == "downdiagonalstrike") {
- addNotation(DownDiagonalStrike);
- } else if (notation == "verticalstrike") {
- addNotation(VerticalStrike);
- } else if (notation == "horizontalstrike") {
- addNotation(HorizontalStrike);
- } else if (notation == "updiagonalarrow") {
- addNotation(UpDiagonalArrow);
- } else if (notation == "phasorangle") {
- addNotation(PhasorAngle);
- } else if (notation == "box") {
- addNotation(Left);
- addNotation(Right);
- addNotation(Top);
- addNotation(Bottom);
- } else if (notation == "actuarial") {
- addNotation(Right);
- addNotation(Top);
- } else if (notation == "madruwb") {
- addNotation(Right);
- addNotation(Bottom);
- }
- }
+ clearNotations();
+ if (!hasAttribute(notationAttr)) {
+ addNotation(LongDiv); // The default value is longdiv.
return;
}
+ auto& value = attributeWithoutSynchronization(notationAttr);
+ Vector<String> notationsList;
+ String(value).split(' ', notationsList);
+ for (auto& notation : notationsList) {
+ if (notation == "longdiv") {
+ addNotation(LongDiv);
+ } else if (notation == "roundedbox") {
+ addNotation(RoundedBox);
+ } else if (notation == "circle") {
+ addNotation(Circle);
+ } else if (notation == "left") {
+ addNotation(Left);
+ } else if (notation == "right") {
+ addNotation(Right);
+ } else if (notation == "top") {
+ addNotation(Top);
+ } else if (notation == "bottom") {
+ addNotation(Bottom);
+ } else if (notation == "updiagonalstrike") {
+ addNotation(UpDiagonalStrike);
+ } else if (notation == "downdiagonalstrike") {
+ addNotation(DownDiagonalStrike);
+ } else if (notation == "verticalstrike") {
+ addNotation(VerticalStrike);
+ } else if (notation == "horizontalstrike") {
+ addNotation(HorizontalStrike);
+ } else if (notation == "updiagonalarrow") {
+ addNotation(UpDiagonalArrow);
+ } else if (notation == "phasorangle") {
+ addNotation(PhasorAngle);
+ } else if (notation == "box") {
+ addNotation(Left);
+ addNotation(Right);
+ addNotation(Top);
+ addNotation(Bottom);
+ } else if (notation == "actuarial") {
+ addNotation(Right);
+ addNotation(Top);
+ } else if (notation == "madruwb") {
+ addNotation(Right);
+ addNotation(Bottom);
+ }
+ }
+}
+bool MathMLMencloseElement::hasNotation(MencloseNotationFlag notationFlag)
+{
+ if (!m_notationFlags)
+ parseNotationAttribute();
+ return m_notationFlags.value() & notationFlag;
+}
+
+void MathMLMencloseElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
+{
+ if (name == notationAttr)
+ m_notationFlags = Nullopt;
+
MathMLInlineContainerElement::parseAttribute(name, value);
}
Modified: trunk/Source/WebCore/mathml/MathMLMencloseElement.h (204720 => 204721)
--- trunk/Source/WebCore/mathml/MathMLMencloseElement.h 2016-08-22 16:13:28 UTC (rev 204720)
+++ trunk/Source/WebCore/mathml/MathMLMencloseElement.h 2016-08-22 16:18:09 UTC (rev 204721)
@@ -52,15 +52,16 @@
PhasorAngle = 1 << 13 // FIXME: phasorangle is not implemented. See http://wkb.ug/127466
// We do not implement the Radical notation. Authors should instead use the <msqrt> element.
};
- bool hasNotation(MencloseNotationFlag notationFlag) const { return m_notationFlags & notationFlag; }
+ bool hasNotation(MencloseNotationFlag);
private:
MathMLMencloseElement(const QualifiedName&, Document&);
RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
void parseAttribute(const QualifiedName&, const AtomicString&) final;
+ void parseNotationAttribute();
void clearNotations() { m_notationFlags = 0; }
- void addNotation(MencloseNotationFlag notationFlag) { m_notationFlags |= notationFlag; }
- unsigned short m_notationFlags;
+ void addNotation(MencloseNotationFlag notationFlag) { m_notationFlags.value() |= notationFlag; }
+ Optional<uint16_t> m_notationFlags;
};
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes