Closed Bug 1424468 Opened 7 years ago Closed 6 years ago

Stop using Encoding::ForName in HTML parser

Categories

(Core :: DOM: HTML Parser, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
mozilla59
Tracking Status
firefox59 --- fixed

People

(Reporter: emk, Assigned: emk)

References

Details

Attachments

(1 file)

This is the last consumer of Encoding::ForName in m-c/c-c.
Comment on attachment 8935994 [details]
Bug 1424468 - Stop using Encoding::ForName in HTML parser.

https://reviewboard.mozilla.org/r/206844/#review212658

Thank you and hooray for making `Encoding::ForName` obsolete! This looks correct to me, but it's unclear to me if using nsString in a union is something that we are supposed to allow in the codebase, so requesting review from the owner of XPCOM strings, too.
Attachment #8935994 - Flags: review?(hsivonen) → review+
Comment on attachment 8935994 [details]
Bug 1424468 - Stop using Encoding::ForName in HTML parser.

Somehow the additional review request wasn't reflected to Bugzilla.
Attachment #8935994 - Flags: review?(dbaron)
FYI, non-trivial class in union is a new feature since C++11.
I think I'd pass that question on to Nathan, since I think it's the general question stated in comment 4.

(I'm also curious how it works under the hood, and what the performance characteristics are.)
Flags: needinfo?(nfroyd)
Non-trivial classes in unions work more-or-less like you expect them to: you need to manually construct them with placement new when they become active and manually destruct them when they become inactive.  There should be virtually no performance difference.

I wonder if we shouldn't be using mozilla::Variant to represent this, since that's the type-safe way to do unions in our codebase.  Ideally, we'd tie it to the value of mOpCode as well, so we couldn't have the values of the union being out-of-sync with the value of mOpCode (or vice versa), but maybe that'd be too big of a project to tackle here.  It'd be larger, and maybe slightly slower, but perhaps that'd be OK for this code?  It looks like we'd have to use Maybe<Variant<const Encoding*, nsString>>, though, because the union isn't really initialized from the moment the object is constructed?  Is that correct?
Flags: needinfo?(nfroyd) → needinfo?(VYV03354)
Variant<const Encoding*, nsString> will not take less space than const Encoding* + nsString.
I'd just add a `const Encoding*` member to nsHtml5SpeculativeLoad if a union is undesiable and the size increase is acceptable for HTML5 parser. Henri, what do you think?
Flags: needinfo?(VYV03354) → needinfo?(hsivonen)
Size increase is undesirable but not totally out of the question. Still, Variant doesn't make sense if it doesn't subsume mOpCode into the variant discriminant, and doing that seems messy in terms of code readability.

My preference is landing the patch as-is, considering that comment 6 doesn't appear to rule that option out.
Flags: needinfo?(hsivonen)
Pushed by VYV03354@nifty.ne.jp:
https://hg.mozilla.org/integration/autoland/rev/c7398a75d48d
Stop using Encoding::ForName in HTML parser. r=hsivonen
Priority: -- → P2
Assignee: nobody → VYV03354
Status: NEW → ASSIGNED
https://hg.mozilla.org/mozilla-central/rev/c7398a75d48d
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
Blocks: 1425217
Comment on attachment 8935994 [details]
Bug 1424468 - Stop using Encoding::ForName in HTML parser.

https://reviewboard.mozilla.org/r/206844/#review217992

ok, r=dbaron, although it seems like it might be safer to use only a small set of getters/setters to access those two members in a single place rather than spreading the accesses around
Attachment #8935994 - Flags: review?(dbaron) → review+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: