Closed Bug 355451 Opened 18 years ago Closed 18 years ago

Be more efficient about creating HTML element

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: sicking, Assigned: sicking)

References

Details

Attachments

(1 file)

NS_NewHTMLElement acts case insensivly to the local name of the nodeinfo passed in when creating HTML elements. So that means that if you create a nodeinfo with an uppercase name 'INPUT' we'll still create an nsHTMLInputElement, as well as give it a nodeinfo with a lowercase localname.

However it's much more efficient to lowercase the name before creating the nodeinfo. First of all callers run the risk of looking up the localname atom and the nodeinfo in vain since we'll just dicard them inside NS_NewHTMLElement. 

Also, it create inconsistent behaviour since only 'supported' element names are lowercased, if you try to create a 'FOOBAR' html element you'll get one with an uppercase localname atom.

Additionally all callers lowercase the name for known elements anyway. The only caller the doesn't lowercase names is nsHTMLFragmentContentSink, which doesn't lowercase names for unknown elements.

Patch to change this so that all callers lowercase and making NS_NewHTMLElement not lowercase comming up. I also removed nsDocument::CreateElement since NS_NewElement does the exact same thing (although with arguments in reverse order).
Attached patch Patch to fixSplinter Review
Attachment #241253 - Flags: superreview?(jst)
Attachment #241253 - Flags: review?(jst)
Comment on attachment 241253 [details] [diff] [review]
Patch to fix

r+sr=jst
Attachment #241253 - Flags: superreview?(jst)
Attachment #241253 - Flags: superreview+
Attachment #241253 - Flags: review?(jst)
Attachment #241253 - Flags: review+
Checked in.
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Summary: Be more efficitent about creating HTML element → Be more efficient about creating HTML element
Comment on attachment 241253 [details] [diff] [review]
Patch to fix

>+  NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX, "aNodeType is out of bounds");
So what does it mean if I hit this assertion? Minimal testcase is <o:p></o:p>
(In reply to comment #4)
> (From update of attachment 241253 [details] [diff] [review] [edit])
> >+  NS_ASSERTION(aNodeType <= NS_HTML_TAG_MAX, "aNodeType is out of bounds");
> So what does it mean if I hit this assertion? Minimal testcase is <o:p></o:p>

That the assertion is wrong, since eHTMLTag_userdefined > NS_HTML_TAG_MAX.
Checked in a fix for the assertion.
Comment on attachment 241253 [details] [diff] [review]
Patch to fix

>-  rv = CreateElement(nodeInfo, nodeInfo->NamespaceID(),
>-                     getter_AddRefs(content));
>+  NS_NewElement(getter_AddRefs(content), nodeInfo->NamespaceID(), nodeInfo);
>   NS_ENSURE_SUCCESS(rv, rv);
Oops.
Blocks: 590870
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: