Open Bug 2043161 Opened 4 months ago Updated 4 months ago

Optimize representation of common enum attributes in the parser

Categories

(Core :: DOM: HTML Parser, enhancement)

enhancement

Tracking

()

People

(Reporter: hsivonen, Unassigned)

References

(Blocks 1 open bug)

Details

Enum attributes, notably the type attribute on input and button cause the parser to allocate a StringBuffer, but the StringBuffer gets thrown away in the DOM.

The most obvious fix is to use the atom representation in the parser and then add an atom overload of ParseAttribute as approriate.

We could even start with only the attribute name type as a special case.

The general idea is this:

  • Read through the overloads of Element::ParseAttribute in HTML element classes to come up with a list of names of attributes that are of enum type.
  • List those (under a new macro) in AtomAttributes.h.
  • Regenerate the HTML parser.
  • Introduce an overload of nsAttrValue::ParseEnumValue that takes value as nsAtom* and takes a table where each item contains an nsAttrValue::EnumTableEntry (as in the current table) and the nsGkAtoms atom for the string. Make the implementation take the lowercase atom for the incoming atom and pointer-compare that against the table instead of comparing the strings. If the incoming atom was mixed-case, use that atom in attribute storage.
  • Introduce no-op virtual function Element::ParseEnumAttribute that takes value as atom and assumes no namespace.
  • Override this method next to each enum-aware pre-existing override of Element::ParseAttribute on HTML elements, only check for enum attributes, and use the new nsAttrValue::ParseEnumValue overload from above.
  • Call the Element::ParseEnumAttribute method in Element::SetNoNameSpaceAttrOnNewlyCreatedElement (in an else branch for if (valueAtom->GetLength() == 1)).
You need to log in before you can comment on or make changes to this bug.