Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbetz committed Mar 1, 2022
1 parent 2bd4286 commit a4abdcd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions interpreter/interpretable.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,12 @@ type evalVarArgs struct {
}

// NewCall creates a new call Interpretable.
func NewCall(id int64, function, overload string, args []Interpretable, trait int, impl functions.FunctionOp) InterpretableCall {
func NewCall(id int64, function, overload string, args []Interpretable, impl functions.FunctionOp) InterpretableCall {
return &evalVarArgs{
id: id,
function: function,
overload: overload,
args: args,
trait: trait,
impl: impl,
}
}
Expand Down
4 changes: 2 additions & 2 deletions interpreter/interpreter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ var (

func BenchmarkInterpreter(b *testing.B) {
for _, tst := range testData {
prg, vars, err := program(b, &tst, Optimize())
prg, vars, err := program(b, &tst, Optimize(), CompileRegexConstants(MatchesRegexOptimization))
if err != nil {
b.Fatal(err)
}
Expand All @@ -1349,7 +1349,7 @@ func BenchmarkInterpreter(b *testing.B) {

func BenchmarkInterpreter_Parallel(b *testing.B) {
for _, tst := range testData {
prg, vars, err := program(b, &tst, Optimize())
prg, vars, err := program(b, &tst, Optimize(), CompileRegexConstants(MatchesRegexOptimization))
if err != nil {
b.Fatal(err)
}
Expand Down
5 changes: 4 additions & 1 deletion interpreter/optimizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/google/cel-go/common/types/ref"
)

// MatchesRegexOptimization optimizes the 'matches' standard library function by compiling the regex pattern and
// reporting any compilation errors at program creation time, and using the compiled regex pattern for all function
// call invocations.
var MatchesRegexOptimization = &RegexOptimization{
Function: "matches",
RegexIndex: 1,
Expand All @@ -29,7 +32,7 @@ var MatchesRegexOptimization = &RegexOptimization{
if err != nil {
return nil, err
}
return NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), 0, func(values ...ref.Val) ref.Val {
return NewCall(call.ID(), call.Function(), call.OverloadID(), call.Args(), func(values ...ref.Val) ref.Val {
if len(values) != 2 {
return types.NoSuchOverloadErr()
}
Expand Down

0 comments on commit a4abdcd

Please sign in to comment.