Skip to content

Regex-free IPv4 parser guts (strict four-part + inet_aton) - #214

Closed
kleinron wants to merge 1 commit into
whitequark:mainfrom
kleinron:main
Closed

kleinron wants to merge 1 commit into
whitequark:mainfrom
kleinron:main

Conversation

@kleinron

Copy link
Copy Markdown

Summary

In-tree IPv4 parser guts swap (MIT): regex-free hand scanners for strict four-part + loose/inet_aton + CIDR split. No new deps; no @kleinron/ipv4 import. Public IPv4 API and accept set unchanged; IPv6 transitional regexes that reuse ipv4Part stay.

Motivation / benches

Microbench tables below were measured on @kleinron/ipv4 using the same algorithms (not timed on this fork). Please re-bench here if useful.

Full tables: https://github.com/kleinron/ipv4/blob/main/bench/RESULTS.md
Highlight: isValidFourPartDecimal

API (corpus) Δ vs ipaddr.js@2.5.0 (neg = faster)
isValidFourPartDecimal mixed / accept / reject −99.3% / −87.5% / −99.7%
isValid loose mixed / accept / reject −84.5% / −76.6% / −84.9%
parse strict accept −76.8%
parse loose accept −80.5%
parse / parseCIDR reject–mixed more modest (≈ −6% to −20%)
parseCIDR accept −51.1%

Test plan

  • Existing suite green (70/70 on the fork)
  • ESLint clean
  • Upstream CI

* Replace IPv4 parser internals with regex-free scanners

Port the strict four-part digit scanner and loose inet_aton digit/base
scanner in-tree so IPv4.isValid / parse / parseCIDR /
isValidFourPartDecimal no longer use RegExp. Keep the public API and
IPv6 transitional ipv4Part pattern unchanged for a small upstreamable
diff.

* Harden parseIntAutoDigits against empty digit spans

Throw when start >= end, matching @kleinron/ipv4, so a caller bug
cannot silently return 0 from an empty range.

---------

Co-authored-by: Ron Klein <1203923+kleinron@users.noreply.github.com>
@whitequark

Copy link
Copy Markdown
Owner

Not interested in maintaining this, sorry.

@whitequark whitequark closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants