Skip to content

Commit

Permalink
Fix static check warning: calling regexp.Match in a loop has poor per…
Browse files Browse the repository at this point in the history
…formance, consider using regexp.Compile (#324)

Co-authored-by: Anqi <[email protected]>
  • Loading branch information
haoxins and Nicole00 authored Apr 2, 2024
1 parent 150403c commit 9a0ce41
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}
Expand Down

0 comments on commit 9a0ce41

Please sign in to comment.