Cache static regexes in docx_ops via LazyLock #65

Merged
parkerhdavis merged 1 commit from lazy-regex-cache into main 2026-05-21 12:52:41 -06:00
parkerhdavis commented 2026-05-21 12:52:20 -06:00 (Migrated from github.com)

Summary

  • Twenty-plus call sites in `docx_ops.rs` were rebuilding the same handful of hardcoded regex patterns on every call. Lift the static ones into module-level `LazyLock` values so each pattern is compiled once at first use and shared thereafter.
  • Each former `let xxx_re = Regex::new(...).expect(...)` is now `let xxx_re: &Regex = &CACHED_RE;`, keeping downstream usage of the local name unchanged.
  • Dynamic regexes built with `format!()` (per-SDT-id patterns) stay inline. One static that was only referenced from a test-only helper (`find_sdt_variables`) stays inline too — no point caching what production code never reaches.

Test plan

  • `make check`
  • `make lint`
  • `make test` — 93/93 passing
## Summary - Twenty-plus call sites in \`docx_ops.rs\` were rebuilding the same handful of hardcoded regex patterns on every call. Lift the static ones into module-level \`LazyLock<Regex>\` values so each pattern is compiled once at first use and shared thereafter. - Each former \`let xxx_re = Regex::new(...).expect(...)\` is now \`let xxx_re: &Regex = &CACHED_RE;\`, keeping downstream usage of the local name unchanged. - Dynamic regexes built with \`format!()\` (per-SDT-id patterns) stay inline. One static that was only referenced from a test-only helper (\`find_sdt_variables\`) stays inline too — no point caching what production code never reaches. ## Test plan - [x] \`make check\` - [x] \`make lint\` - [x] \`make test\` — 93/93 passing
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
parker/lily!65
No description provided.