refactor: fork the URI and URL engines behind static dispatch#59
Merged
Conversation
The host parser and the recomposition serializer were each forked into per-spec units (UriHostParser/UrlHostParser, UriSerializer/UrlSerializer), but their tests stayed as single combined files still named after the removed unified types. Split each to match the source: - HostParserTest -> UriHostParserTest + UrlHostParserTest - SerializerTest -> UriSerializerTest + UrlSerializerTest + SerializeSharedTest (the last covering the shared authority serializer) Every test moves verbatim; the split is a clean partition since each case exercises exactly one parser/serializer. Also move the shared IP-literal bracket delimiters (BRACKET_OPEN/BRACKET_CLOSE) into the neutral HostParsing file so the two host parsers reference one definition instead of each keeping a private copy. NOT_FOUND stays file-private per the existing per-file sentinel convention in the host package. No behaviour change and no public API change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three internal files — the host parser, the IPv4 parser, and the recomposition
serializer — were each a single object that took a profile argument and branched
if (profile.isWhatwg) … else …at runtime to serve both the RFC 3986 (URI) andthe WHATWG (URL) code paths. Every caller of those objects is single-profile, so
that runtime branch was hidden control flow with no benefit.
This forks each of the three into a per-spec unit and lets each caller dispatch
statically:
Serializer→UriSerializer+UrlSerializer, with the shared authority andquery/fragment helpers hoisted into
SerializeShared.Ipv4→Ipv4Rfc3986+Ipv4Whatwg; the shared serialization, octet packing,and
endsInANumberremain onIpv4.HostParser→UriHostParser+UrlHostParser, with the shared bracket helpersin
HostParsing.The paired spec units never reference each other — genuinely shared code lives in
the three neutral files above — so a change to the URL path can no longer silently
affect the URI path, and vice versa.
With the three dispatchers gone, the
ParseProfileenum had no remaining callersand is removed. Separately, the shared path model
UrlPath— used by the URI path,the reference resolver, and the normalizer as well as by URL parsing — is renamed
ComponentPathso its name no longer implies it is WHATWG-specific. As a smallcleanup, a duplicate private
SLASHconstant inUriNormalizeris dropped in favourof the shared one introduced by the serializer split.
No behaviour change and no public API change: every moved function body is preserved
verbatim, the full existing conformance suite (URL, URI, host, IDNA, serializer,
resolver, IPv4) passes unchanged, the binary-compatibility snapshots are untouched
(
apiCheckclean), and there are no generated-table or codegen edits.