@@ -70,7 +70,8 @@ func (m *valueMatcher) transitionOn(val []byte) []*fieldMatcher {
7070 return transitionDfa (fields .startDfa , val , transitions )
7171
7272 default :
73- // no dfa, no singleton, nothing to do
73+ // no dfa, no singleton, nothing to do, this probably can't happen because a flattener
74+ // shouldn't preserve a field that hasn't appeared in a pattern
7475 return transitions
7576 }
7677}
@@ -116,6 +117,8 @@ func (m *valueMatcher) addTransition(val typedVal) *fieldMatcher {
116117 var newNfa * smallTable [* nfaStepList ]
117118 newNfa , nextField = makeShellStyleAutomaton (valBytes , nil )
118119 newDfa = nfa2Dfa (newNfa )
120+ case prefixType :
121+ newDfa , nextField = makePrefixAutomaton (valBytes , nil )
119122 default :
120123 panic ("unknown value type" )
121124 }
@@ -145,6 +148,11 @@ func (m *valueMatcher) addTransition(val typedVal) *fieldMatcher {
145148 fields .startDfa = nfa2Dfa (newAutomaton )
146149 m .update (fields )
147150 return nextField
151+ case prefixType :
152+ newAutomaton , nextField := makePrefixAutomaton (valBytes , nil )
153+ fields .startDfa = newAutomaton
154+ m .update (fields )
155+ return nextField
148156 default :
149157 panic ("unknown value type" )
150158 }
@@ -171,8 +179,10 @@ func (m *valueMatcher) addTransition(val typedVal) *fieldMatcher {
171179 var newNfa * smallTable [* nfaStepList ]
172180 newNfa , nextField = makeShellStyleAutomaton (valBytes , nil )
173181 newDfa = nfa2Dfa (newNfa )
182+ case prefixType :
183+ newDfa , nextField = makePrefixAutomaton (valBytes , nil )
174184 default :
175- panic ("unknown val type" )
185+ panic ("unknown value type" )
176186 }
177187
178188 // now table is ready for use, nuke singleton to signal threads to use it
@@ -183,6 +193,29 @@ func (m *valueMatcher) addTransition(val typedVal) *fieldMatcher {
183193 return nextField
184194}
185195
196+ func makePrefixAutomaton (val []byte , useThisTransition * fieldMatcher ) (* smallTable [* dfaStep ], * fieldMatcher ) {
197+ var nextField * fieldMatcher
198+
199+ if useThisTransition != nil {
200+ nextField = useThisTransition
201+ } else {
202+ nextField = newFieldMatcher ()
203+ }
204+ return onePrefixStep (val , 0 , nextField ), nextField
205+ }
206+
207+ func onePrefixStep (val []byte , index int , nextField * fieldMatcher ) * smallTable [* dfaStep ] {
208+ var nextStep * dfaStep
209+
210+ // have to stop one short to skip the closing "
211+ if index == len (val )- 2 {
212+ nextStep = & dfaStep {table : newSmallTable [* dfaStep ](), fieldTransitions : []* fieldMatcher {nextField }}
213+ } else {
214+ nextStep = & dfaStep {table : onePrefixStep (val , index + 1 , nextField )}
215+ }
216+ return makeSmallDfaTable (nil , []byte {val [index ]}, []* dfaStep {nextStep })
217+ }
218+
186219// makeStringAutomaton creates a utf8-based automaton from a literal string
187220// using smallTables. Note the addition of a valueTerminator. The implementation
188221// is recursive because this allows the use of the makeSmallDfaTable call, which
0 commit comments