From 9a0ce4167ddb539efd85f3833bca5833af74ebed Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Tue, 2 Apr 2024 17:20:00 +0800 Subject: [PATCH] Fix static check warning: calling regexp.Match in a loop has poor performance, consider using regexp.Compile (#324) Co-authored-by: Anqi --- result_set.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/result_set.go b/result_set.go index e73c4415..88334985 100644 --- a/result_set.go +++ b/result_set.go @@ -1352,6 +1352,10 @@ func (res ResultSet) MakeDotGraphByStruct() string { // generate profiling data for both Row and TCK formats. func MakeProfilingData(planNodeDesc *graph.PlanNodeDescription, isTckFmt bool) string { var profileArr []string + re, err := regexp.Compile(`^[^{(\[]\w+`) + if err != nil { + panic(err) + } for i, profile := range planNodeDesc.GetProfiles() { var statArr []string statArr = append(statArr, fmt.Sprintf("\"version\":%d", i)) @@ -1363,7 +1367,7 @@ func MakeProfilingData(planNodeDesc *graph.PlanNodeDescription, isTckFmt bool) s } for k, v := range profile.GetOtherStats() { s := string(v) - if matched, err := regexp.Match(`^[^{(\[]\w+`, v); err == nil && matched { + if matched := re.Match(v); matched { if !strings.HasPrefix(s, "\"") { s = fmt.Sprintf("\"%s", s) }