-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kaizen: add equals-ignore-case pattern (#340)
* kaizen: add equals-ignore-case pattern addresses: #186 Signed-off-by: Tim Bray <[email protected]> * reset CI/CD to not fail on slowdown Signed-off-by: Tim Bray <[email protected]> * enable github token for benchmarker Signed-off-by: Tim Bray <[email protected]> --------- Signed-off-by: Tim Bray <[email protected]>
- Loading branch information
Showing
18 changed files
with
959 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The only purpose of this makefile is to run code_gen/code_gen, which will rebuild the case_folding.go file if | ||
# it is more than three months out of date | ||
casefold: | ||
@ cd code_gen && go build && cd .. | ||
@ code_gen/code_gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package quamina | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"unicode/utf8" | ||
) | ||
|
||
func readMonocaseSpecial(pb *patternBuild, valsIn []typedVal) (pathVals []typedVal, err error) { | ||
t, err := pb.jd.Token() | ||
if err != nil { | ||
return | ||
} | ||
pathVals = valsIn | ||
|
||
monocaseString, ok := t.(string) | ||
if !ok { | ||
err = errors.New("value for 'prefix' must be a string") | ||
return | ||
} | ||
val := typedVal{ | ||
vType: monocaseType, | ||
val: `"` + monocaseString + `"`, | ||
} | ||
pathVals = append(pathVals, val) | ||
|
||
// has to be } or tokenizer will throw error | ||
_, err = pb.jd.Token() | ||
return | ||
} | ||
|
||
// makeMonocaseFA builds a FA to match "ignore-case" patterns. The Unicode Standard specifies algorithm 3.13, | ||
// relying on the file CaseFolding.txt in the Unicode Character Database. This function uses the "Simple" flavor | ||
// of casefolding, i.e. the lines in CaseFolding.txt that are marked with "C". The discussion in the Unicode | ||
// standard doesn't mention this, but the algorithm essentially replaces upper-case characters with lower-case | ||
// equivalents. | ||
// We need to exercise caution to keep from creating states wastefully. For "CAT", after matching '"', | ||
// you transition on either 'c' or 'C' but in this particular case you want to transition to the same | ||
// next state. Note that there are many characters in Unicode where the upper and lower case forms are | ||
// multi-byte and in fact not even the same number of bytes. So in that case you need two paths forward that step | ||
// through the bytes of each form and then rejoin to arrive at a state. Also note | ||
// that in many cases the upper/lower case versions of a rune have leading bytes in common | ||
func makeMonocaseFA(val []byte, pp printer) (*smallTable, *fieldMatcher) { | ||
fm := newFieldMatcher() | ||
index := 0 | ||
table := newSmallTable() // start state | ||
startTable := table | ||
var nextStep *faNext | ||
for index < len(val) { | ||
var orig, alt []byte | ||
r, width := utf8.DecodeRune(val[index:]) | ||
orig = val[index : index+width] | ||
altRune, ok := caseFoldingPairs[r] | ||
if ok { | ||
alt = make([]byte, utf8.RuneLen(altRune)) | ||
utf8.EncodeRune(alt, altRune) | ||
} | ||
nextStep = &faNext{states: []*faState{{table: newSmallTable()}}} | ||
pp.labelTable(nextStep.states[0].table, fmt.Sprintf("On %d, alt=%v", val[index], alt)) | ||
if alt == nil { | ||
// easy case, no casefolding issues. We should maybe try to coalesce these | ||
// no-casefolding sections and only call makeFAFragment once for all of them | ||
origFA := makeFAFragment(orig, nextStep, pp) | ||
table.addByteStep(orig[0], origFA) | ||
} else { | ||
// two paths to next state | ||
// but they might have a common prefix | ||
var commonPrefix int | ||
for commonPrefix = 0; orig[commonPrefix] == alt[commonPrefix]; commonPrefix++ { | ||
prefixNext := &faNext{states: []*faState{{table: newSmallTable()}}} | ||
table.addByteStep(orig[commonPrefix], prefixNext) | ||
table = prefixNext.states[0].table | ||
pp.labelTable(table, fmt.Sprintf("common prologue on %v", orig[commonPrefix])) | ||
} | ||
// now build automata for the orig and alt versions of the char | ||
// TODO: make sure that makeFAFragment works with length == 1 | ||
origFA := makeFAFragment(orig[commonPrefix:], nextStep, pp) | ||
altFA := makeFAFragment(alt[commonPrefix:], nextStep, pp) | ||
table.addByteStep(orig[commonPrefix], origFA) | ||
table.addByteStep(alt[commonPrefix], altFA) | ||
} | ||
table = nextStep.states[0].table | ||
index += width | ||
} | ||
laststate := &faState{table: newSmallTable(), fieldTransitions: []*fieldMatcher{fm}} | ||
lastStep := &faNext{states: []*faState{laststate}} | ||
nextStep.states[0].table.addByteStep(valueTerminator, lastStep) | ||
return startTable, fm | ||
} |
Oops, something went wrong.
6d34146
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Go Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.20
.BenchmarkCityLots
6836
ns/op 823 B/op 33 allocs/op5592
ns/op 773 B/op 31 allocs/op1.22
BenchmarkCityLots - ns/op
6836
ns/op5592
ns/op1.22
Benchmark_JsonFlattner_Evaluate_ContextFields
1217
ns/op 96 B/op 8 allocs/op726.2
ns/op 56 B/op 4 allocs/op1.68
Benchmark_JsonFlattner_Evaluate_ContextFields - ns/op
1217
ns/op726.2
ns/op1.68
Benchmark_JsonFlattner_Evaluate_ContextFields - B/op
96
B/op56
B/op1.71
Benchmark_JsonFlattner_Evaluate_ContextFields - allocs/op
8
allocs/op4
allocs/op2
This comment was automatically generated by workflow using github-action-benchmark.