Skip to content

Commit

Permalink
Merge pull request #17652 from callthingsoff/make_Regexp_global
Browse files Browse the repository at this point in the history
all: make regexp.Regexp variables global when not using configuration…
  • Loading branch information
ahrtr authored Mar 27, 2024
2 parents 647b7eb + f3daf5e commit f1836fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions client/pkg/testutil/leak.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ running(leaking) after all tests.
...
}
*/
var normalizedRegexp = regexp.MustCompile(`\(0[0-9a-fx, ]*\)`)

func CheckLeakedGoroutine() bool {
gs := interestingGoroutines()
if len(gs) == 0 {
return false
}

stackCount := make(map[string]int)
re := regexp.MustCompile(`\(0[0-9a-fx, ]*\)`)
for _, g := range gs {
// strip out pointer arguments in first function of stack dump
normalized := string(re.ReplaceAll([]byte(g), []byte("(...)")))
normalized := string(normalizedRegexp.ReplaceAll([]byte(g), []byte("(...)")))
stackCount[normalized]++
}

Expand Down
5 changes: 3 additions & 2 deletions etcdctl/ctlv3/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func addHexPrefix(s string) string {
return string(ns)
}

var argsRegexp = regexp.MustCompile(`"(?:[^"\\]|\\.)*"|'[^']*'|[^'"\s]\S*[^'"\s]?`)

func Argify(s string) []string {
r := regexp.MustCompile(`"(?:[^"\\]|\\.)*"|'[^']*'|[^'"\s]\S*[^'"\s]?`)
args := r.FindAllString(s, -1)
args := argsRegexp.FindAllString(s, -1)
for i := range args {
if len(args[i]) == 0 {
continue
Expand Down

0 comments on commit f1836fc

Please sign in to comment.