Skip to content

perf: Replace ISO date parser's split/collect with fixed-position structural checks#6

Draft
Copilot wants to merge 3 commits intots/address-quality-auditfrom
copilot/sub-pr-5
Draft

perf: Replace ISO date parser's split/collect with fixed-position structural checks#6
Copilot wants to merge 3 commits intots/address-quality-auditfrom
copilot/sub-pr-5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 22, 2026

The ISO format parser (YYYY-MM, YYYY-MM-DD) was using split().collect::<Vec<_>>(), allocating a Vec on every successful parse — inconsistent with the already-optimized slash-format parser.

Changes

  • New parse_iso_date dispatcher: selects between two dedicated functions based on string length (7 or 10); emits a "Too many - separators" error for lengths with excess hyphens
  • New parse_iso_7: handles YYYY-MM (exactly 7 bytes) — validates digits at fixed positions 0–3 and 5–6, and a - at position 4, using a single compound boolean; no loop, no allocation
  • New parse_iso_10: handles YYYY-MM-DD (exactly 10 bytes) — validates digits at fixed positions 0–3, 5–6, and 8–9, and - separators at positions 4 and 7, using a single compound boolean; no loop, no allocation
  • Removed parse_iso_month_year and parse_iso_full_date: consolidated into the two new functions
// Before — allocates Vec on every successful parse
let parts: Vec<&str> = trimmed.split(DATE_SEPARATOR).map(str::trim).collect();
match parts.len() { ... }

// After — length dispatch into fixed-position structural checks; zero allocation
Self::parse_iso_date(trimmed)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Feb 22, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  src/lib.rs  33% smaller

…ocations

Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ISO parsing optimization in address quality audit perf: Replace ISO date parser's split/collect with allocation-free byte walker Feb 22, 2026
Copilot AI requested a review from tcrypt25519 February 22, 2026 09:40
Copy link
Copy Markdown
Owner

@tcrypt25519 tcrypt25519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot There's no reason to bridge like 20 times for this. You can get it down to 2 if you do this with separate fns for 8 and 10.

Structural ISO 8601 date validation algorithm

Goal: validate only the character structure of a string as either:

YYYY-MM (length 8)

YYYY-MM-DD (length 10)

No semantic checks. Only shape.


Step-by-step algorithm

  1. Read input

Let s be the character array.

Let len be its length.


  1. Length guard

if len != 8 AND len != 10:
return false


  1. Initialize counters

digitSum = 0
hyphenSum = 0


  1. Validate required digit positions

Always check:

indices: 0,1,2,3,5,6

For each index i above:

if s[i] is digit:
digitSum += 1

If len == 10, also check:

indices: 8,9


  1. Validate hyphen positions

Always check:

if s[4] == '-':
hyphenSum += 1

If len == 10:

if s[7] == '-':
hyphenSum += 1


  1. Final structural verdict

if len == 8:
return digitSum == 6 AND hyphenSum == 1

if len == 10:
return digitSum == 8 AND hyphenSum == 2


  1. End

Result is true only if the string matches the required structural layout exactly.

…parse_iso_7 + parse_iso_10)

Co-authored-by: tcrypt25519 <212655132+tcrypt25519@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot There's no reason to bridge like 20 times for this. You can get it down to 2 if you do this with separate fns for 8 and 10.

Structural ISO 8601 date validation algorithm...

Done in e2d4624. The byte-walker is replaced by two fixed-position functions: parse_iso_7 (YYYY-MM, 7 bytes) and parse_iso_10 (YYYY-MM-DD, 10 bytes). A thin parse_iso_date dispatcher selects between them by string length. Each inner function does a single compound boolean check on fixed indices — no loop, no allocation. Note: YYYY-MM is 7 bytes (not 8 as listed in the spec), so the dispatch key is 7 and 10.

Copilot AI changed the title perf: Replace ISO date parser's split/collect with allocation-free byte walker perf: Replace ISO date parser's split/collect with fixed-position structural checks Feb 22, 2026
Copilot AI requested a review from tcrypt25519 February 22, 2026 18:39
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