Skip to content

Commit

Permalink
Optimise IntersectStree for matching subject literals
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Feb 3, 2025
1 parent e331d07 commit 169a39d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/sublist.go
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,13 @@ func IntersectStree[T any](st *stree.SubjectTree[T], sl *Sublist, cb func(subj [

func intersectStree[T any](st *stree.SubjectTree[T], r *level, subj []byte, cb func(subj []byte, entry *T)) {
if r.numNodes() == 0 {
st.Match(subj, cb)
// For wildcards we can't avoid Match, but if it's a literal subject at
// this point, using Find is considerably cheaper.
if subjectHasWildcard(bytesToString(subj)) {
st.Match(subj, cb)
} else if e, ok := st.Find(subj); ok {
cb(subj, e)
}
return
}
nsubj := subj
Expand Down

0 comments on commit 169a39d

Please sign in to comment.