Skip to content

cleanup: extract cachedParse helper for parse-result reuse#586

Open
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:cachephwc
Open

cleanup: extract cachedParse helper for parse-result reuse#586
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:cachephwc

Conversation

@jvoisin

@jvoisin jvoisin commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

WrapHtml, WrapInnerHtml, and eachNodeHtml each open-coded the same lookup-or-parse-and-store sequence against a map[string][]*html.Node keyed by the context node's name. Extract that 4-line sequence into a tiny cachedParseHtmlWithContext(cache, htmlStr, context) helper; each call site becomes a linear, closure-free loop and the only duplicated bit (the cache lookup) lives in one place.

WrapHtml, WrapInnerHtml, and eachNodeHtml each open-coded the same
lookup-or-parse-and-store sequence against a map[string][]*html.Node
keyed by the context node's name. Extract that 4-line sequence into
a tiny cachedParseHtmlWithContext(cache, htmlStr, context) helper; each call
site becomes a linear, closure-free loop and the only duplicated bit (the cache
lookup) lives in one place.
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.

1 participant