Open Bug 1489042 Opened 8 years ago Updated 10 months ago

Make StringBuilder keep track of whether all units are in the Latin1 range

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: hsivonen, Unassigned)

References

(Blocks 1 open bug)

Details

Once we have bug 1449849, we should avoid converting to UTF-16 and back to Latin1 when InnerHTML getting returns content that's all in the Latin1 range to SpiderMonkey. Text nodes know if they are Latin1. Static atoms and literals are in the ASCII range. Attribute values and dynamic atoms need to be checked at the time of generating the Units.
Component: DOM → DOM: Core & HTML
Depends on: 1561564
No longer depends on: 1449849
Blocks: 1583808
Severity: normal → S3

(In reply to Henri Sivonen (:hsivonen) from comment #0)

Attribute values and dynamic atoms need to be checked at the time of generating the Units.

We could do better: The least costly way of finding out that the serialization as a whole is not going to be Latin1 is encountering a non-Latin1 text node.

Let's do this:

Let have a boolean seenUnicode right about here: https://searchfox.org/firefox-main/rev/1c2b83c1fdb8ba523831bcdb63947f5f7a4cfa5e/dom/base/nsContentUtils.cpp#10585

Let's pass a pointer to the boolean down so that if we get to https://searchfox.org/firefox-main/rev/1c2b83c1fdb8ba523831bcdb63947f5f7a4cfa5e/dom/base/nsContentUtils.cpp#10283 or if is2b returns true at https://searchfox.org/firefox-main/rev/1c2b83c1fdb8ba523831bcdb63947f5f7a4cfa5e/dom/base/nsContentUtils.cpp#10618 , set the flag to true.

If before ToString the flag is true, do the same thing we do now.

If not, traverse the non-text-node units to see if there's any non-Latin1. If there is, do the same thing we do now.

If we saw no non-Latin1, run a Latin1-targeting specialization of ToString.

Hmm. For atoms, we could check staticness in the first pass. Then the second pass would only need to examine attribute values.

You need to log in before you can comment on or make changes to this bug.