diff --git a/CHANGELOG.md b/CHANGELOG.md index e99b749..6f9aaa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- **Dependency**: `github.com/coregx/ahocorasick` v0.2.1 → v0.3.0 — zero-allocation + `Find`/`FindAt` API (returns `(Match, bool)` instead of `*Match`) + ### Planned - Look-around assertions - ARM NEON SIMD support (Go 1.26 `simd/archsimd` intrinsics — [#120](https://github.com/coregx/coregex/issues/120)) diff --git a/ROADMAP.md b/ROADMAP.md index 2f12261..ff03b80 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -103,8 +103,10 @@ v0.12.20 ✅ → Premultiplied/tagged StateIDs, break-at-match DFA determinize, v0.12.21 ✅ → Tagged start states, zero-alloc API (AllIndex iter.Seq), 1100x fewer mallocs, UseDFA for tiny NFA, -32% LangArena ↓ -v0.12.22 (Current) → Lazy memory architecture (Rust Cache model), 5-7x memory - reduction per pattern, WAF adoption unblocked (#158) +v0.12.22 ✅ → Lazy memory architecture (Rust Cache model), 5-7x memory + reduction per pattern, WAF adoption unblocked (#158) + ↓ +v0.12.23 (Current) → ahocorasick v0.3.0 (zero-alloc Find/FindAt API) ↓ v1.0.0-rc → Feature freeze, API locked ↓ diff --git a/go.mod b/go.mod index f8a4a33..bfdc261 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/coregx/coregex go 1.25.4 require ( - github.com/coregx/ahocorasick v0.2.1 + github.com/coregx/ahocorasick v0.3.0 golang.org/x/sys v0.40.0 ) diff --git a/go.sum b/go.sum index f5a6646..1197961 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/coregx/ahocorasick v0.2.1 h1:JsZ5Rb32/SzGiGBl3vIwA8DAnY0+E6BLBhj+4HZsAbo= -github.com/coregx/ahocorasick v0.2.1/go.mod h1:SDcS9KTiwLP8FHNpYSO3Q3mRqrK8SYJAYpygrhcIils= +github.com/coregx/ahocorasick v0.3.0 h1:zKln33RykAkG9/eYh/trl85R6x1YChfEtrDQ3NADMsk= +github.com/coregx/ahocorasick v0.3.0/go.mod h1:SDcS9KTiwLP8FHNpYSO3Q3mRqrK8SYJAYpygrhcIils= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= diff --git a/meta/find.go b/meta/find.go index 108a89b..6aca7e9 100644 --- a/meta/find.go +++ b/meta/find.go @@ -590,8 +590,8 @@ func (e *Engine) findTeddy(haystack []byte) *Match { // Fat Teddy's AVX2 SIMD setup overhead exceeds benefit on small inputs. if e.fatTeddyFallback != nil && len(haystack) < fatTeddySmallHaystackThreshold { atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - match := e.fatTeddyFallback.Find(haystack, 0) - if match == nil { + match, found := e.fatTeddyFallback.Find(haystack, 0) + if !found { return nil } return NewMatch(match.Start, match.End, haystack) @@ -630,8 +630,8 @@ func (e *Engine) findTeddyAt(haystack []byte, at int) *Match { // For Fat Teddy with small haystacks, use Aho-Corasick fallback. if e.fatTeddyFallback != nil && len(haystack) < fatTeddySmallHaystackThreshold { atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - match := e.fatTeddyFallback.FindAt(haystack, at) - if match == nil { + match, found := e.fatTeddyFallback.FindAt(haystack, at) + if !found { return nil } return NewMatch(match.Start, match.End, haystack) @@ -772,8 +772,8 @@ func (e *Engine) findAhoCorasick(haystack []byte) *Match { } atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - m := e.ahoCorasick.Find(haystack, 0) - if m == nil { + m, found := e.ahoCorasick.Find(haystack, 0) + if !found { return nil } return NewMatch(m.Start, m.End, haystack) @@ -786,8 +786,8 @@ func (e *Engine) findAhoCorasickAt(haystack []byte, at int) *Match { } atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - m := e.ahoCorasick.Find(haystack, at) - if m == nil { + m, found := e.ahoCorasick.Find(haystack, at) + if !found { return nil } return NewMatch(m.Start, m.End, haystack) diff --git a/meta/find_indices.go b/meta/find_indices.go index 111d387..eb83211 100644 --- a/meta/find_indices.go +++ b/meta/find_indices.go @@ -1094,8 +1094,8 @@ func (e *Engine) findIndicesAhoCorasick(haystack []byte) (int, int, bool) { } atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - m := e.ahoCorasick.Find(haystack, 0) - if m == nil { + m, found := e.ahoCorasick.Find(haystack, 0) + if !found { return -1, -1, false } return m.Start, m.End, true @@ -1108,8 +1108,8 @@ func (e *Engine) findIndicesAhoCorasickAt(haystack []byte, at int) (int, int, bo } atomic.AddUint64(&e.stats.AhoCorasickSearches, 1) - m := e.ahoCorasick.Find(haystack, at) - if m == nil { + m, found := e.ahoCorasick.Find(haystack, at) + if !found { return -1, -1, false } return m.Start, m.End, true diff --git a/prefilter/ahocorasick.go b/prefilter/ahocorasick.go index bc3d124..b00ce73 100644 --- a/prefilter/ahocorasick.go +++ b/prefilter/ahocorasick.go @@ -54,8 +54,8 @@ func (p *AhoCorasickPrefilter) Find(haystack []byte, start int) int { if start < 0 || start >= len(haystack) { return -1 } - m := p.ac.Find(haystack, start) - if m == nil { + m, found := p.ac.Find(haystack, start) + if !found { return -1 } return m.Start