app/vmselect: use strings.EqualFold instead of strings.ToLower where appropriate

Strings.EqualFold doesn't allocate memory contrary to strings.ToLower if the input string contains uppercase chars
This commit is contained in:
Aliaksandr Valialkin 2024-05-12 10:20:39 +02:00
parent 95608885ea
commit 92de6ea340
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB
4 changed files with 10 additions and 10 deletions

View File

@ -213,11 +213,11 @@ func (p *parser) parseMetricExprOrFuncCall() (Expr, error) {
// Metric epxression or bool expression or None. // Metric epxression or bool expression or None.
if isBool(ident) { if isBool(ident) {
be := &BoolExpr{ be := &BoolExpr{
B: strings.ToLower(ident) == "true", B: strings.EqualFold(ident, "true"),
} }
return be, nil return be, nil
} }
if strings.ToLower(ident) == "none" { if strings.EqualFold(ident, "none") {
nne := &NoneExpr{} nne := &NoneExpr{}
return nne, nil return nne, nil
} }

View File

@ -112,7 +112,7 @@ func binaryOpNeqFunc(bfa *binaryOpFuncArg) ([]*timeseries, error) {
} }
func isUnionFunc(e metricsql.Expr) bool { func isUnionFunc(e metricsql.Expr) bool {
if fe, ok := e.(*metricsql.FuncExpr); ok && (fe.Name == "" || strings.ToLower(fe.Name) == "union") { if fe, ok := e.(*metricsql.FuncExpr); ok && (fe.Name == "" || strings.EqualFold(fe.Name, "union")) {
return true return true
} }
return false return false
@ -303,7 +303,7 @@ func ensureSingleTimeseries(side string, be *metricsql.BinaryOpExpr, tss []*time
func groupJoin(singleTimeseriesSide string, be *metricsql.BinaryOpExpr, rvsLeft, rvsRight, tssLeft, tssRight []*timeseries) ([]*timeseries, []*timeseries, error) { func groupJoin(singleTimeseriesSide string, be *metricsql.BinaryOpExpr, rvsLeft, rvsRight, tssLeft, tssRight []*timeseries) ([]*timeseries, []*timeseries, error) {
joinTags := be.JoinModifier.Args joinTags := be.JoinModifier.Args
var skipTags []string var skipTags []string
if strings.ToLower(be.GroupModifier.Op) == "on" { if strings.EqualFold(be.GroupModifier.Op, "on") {
skipTags = be.GroupModifier.Args skipTags = be.GroupModifier.Args
} }
joinPrefix := "" joinPrefix := ""

View File

@ -542,7 +542,7 @@ func execBinaryOpArgs(qt *querytracer.Tracer, ec *EvalConfig, exprFirst, exprSec
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
if len(tssFirst) == 0 && strings.ToLower(be.Op) != "or" { if len(tssFirst) == 0 && !strings.EqualFold(be.Op, "or") {
// Fast path: there is no sense in executing the exprSecond when exprFirst returns an empty result, // Fast path: there is no sense in executing the exprSecond when exprFirst returns an empty result,
// since the "exprFirst op exprSecond" would return an empty result in any case. // since the "exprFirst op exprSecond" would return an empty result in any case.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3349 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3349
@ -1168,7 +1168,7 @@ func evalInstantRollup(qt *querytracer.Tracer, ec *EvalConfig, funcName string,
return evalExpr(qt, ec, be) return evalExpr(qt, ec, be)
case "rate": case "rate":
if iafc != nil { if iafc != nil {
if strings.ToLower(iafc.ae.Name) != "sum" { if !strings.EqualFold(iafc.ae.Name, "sum") {
qt.Printf("do not apply instant rollup optimization for incremental aggregate %s()", iafc.ae.Name) qt.Printf("do not apply instant rollup optimization for incremental aggregate %s()", iafc.ae.Name)
return evalAt(qt, timestamp, window) return evalAt(qt, timestamp, window)
} }
@ -1214,7 +1214,7 @@ func evalInstantRollup(qt *querytracer.Tracer, ec *EvalConfig, funcName string,
return evalExpr(qt, ec, be) return evalExpr(qt, ec, be)
case "max_over_time": case "max_over_time":
if iafc != nil { if iafc != nil {
if strings.ToLower(iafc.ae.Name) != "max" { if !strings.EqualFold(iafc.ae.Name, "max") {
qt.Printf("do not apply instant rollup optimization for non-max incremental aggregate %s()", iafc.ae.Name) qt.Printf("do not apply instant rollup optimization for non-max incremental aggregate %s()", iafc.ae.Name)
return evalAt(qt, timestamp, window) return evalAt(qt, timestamp, window)
} }
@ -1276,7 +1276,7 @@ func evalInstantRollup(qt *querytracer.Tracer, ec *EvalConfig, funcName string,
return tss, nil return tss, nil
case "min_over_time": case "min_over_time":
if iafc != nil { if iafc != nil {
if strings.ToLower(iafc.ae.Name) != "min" { if !strings.EqualFold(iafc.ae.Name, "min") {
qt.Printf("do not apply instant rollup optimization for non-min incremental aggregate %s()", iafc.ae.Name) qt.Printf("do not apply instant rollup optimization for non-min incremental aggregate %s()", iafc.ae.Name)
return evalAt(qt, timestamp, window) return evalAt(qt, timestamp, window)
} }
@ -1345,7 +1345,7 @@ func evalInstantRollup(qt *querytracer.Tracer, ec *EvalConfig, funcName string,
"increase", "increase",
"increase_pure", "increase_pure",
"sum_over_time": "sum_over_time":
if iafc != nil && strings.ToLower(iafc.ae.Name) != "sum" { if iafc != nil && !strings.EqualFold(iafc.ae.Name, "sum") {
qt.Printf("do not apply instant rollup optimization for non-sum incremental aggregate %s()", iafc.ae.Name) qt.Printf("do not apply instant rollup optimization for non-sum incremental aggregate %s()", iafc.ae.Name)
return evalAt(qt, timestamp, window) return evalAt(qt, timestamp, window)
} }

View File

@ -139,7 +139,7 @@ func maySortResults(e metricsql.Expr) bool {
return false return false
} }
case *metricsql.BinaryOpExpr: case *metricsql.BinaryOpExpr:
if strings.ToLower(v.Op) == "or" { if strings.EqualFold(v.Op, "or") {
// Do not sort results for `a or b` in the same way as Prometheus does. // Do not sort results for `a or b` in the same way as Prometheus does.
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4763 // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4763
return false return false