]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: use internal/lazyregexp for goVersionRx
authorDaniel Martí <mvdan@mvdan.cc>
Sun, 8 Jan 2023 22:56:40 +0000 (22:56 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 20 Jan 2023 09:35:03 +0000 (09:35 +0000)
With benchinit, we see a noticeable improvement in init times:

name     old time/op    new time/op    delta
GoTypes    83.4µs ± 0%    43.7µs ± 1%  -47.57%  (p=0.029 n=4+4)

name     old alloc/op   new alloc/op   delta
GoTypes    26.5kB ± 0%    18.8kB ± 0%  -29.15%  (p=0.029 n=4+4)

name     old allocs/op  new allocs/op  delta
GoTypes       238 ± 0%       154 ± 0%  -35.29%  (p=0.029 n=4+4)

Port the same change to cmd/compile/internal/types and types2.

Updates #26775.

Change-Id: Ia1f7c4a4ce9a22d66e2aa9c9b9c341036993adca
Reviewed-on: https://go-review.googlesource.com/c/go/+/460544
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/types/goversion.go
src/cmd/compile/internal/types2/version.go
src/go/build/deps_test.go
src/go/types/version.go

index 3ece95bf0ac81510af0d684152d48b16e7b716bc..c57493a5cb2a6ed2640a6efd86ada4d2d82fe17a 100644 (file)
@@ -7,8 +7,8 @@ package types
 import (
        "fmt"
        "internal/goversion"
+       "internal/lazyregexp"
        "log"
-       "regexp"
        "strconv"
 
        "cmd/compile/internal/base"
@@ -81,4 +81,4 @@ func currentLang() string {
 
 // goVersionRE is a regular expression that matches the valid
 // arguments to the -lang flag.
-var goVersionRE = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
+var goVersionRE = lazyregexp.New(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
index b649f09c3aa95ad333e1dcad2e4988ea0d549ff1..8fd76a381d9680363e639f7c97d7eaacb9a65c0d 100644 (file)
@@ -7,7 +7,7 @@ package types2
 import (
        "cmd/compile/internal/syntax"
        "fmt"
-       "regexp"
+       "internal/lazyregexp"
        "strconv"
        "strings"
 )
@@ -78,4 +78,4 @@ func parseGoVersion(s string) (v version, err error) {
 }
 
 // goVersionRx matches a Go version string, e.g. "go1.12".
-var goVersionRx = regexp.MustCompile(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
+var goVersionRx = lazyregexp.New(`^go([1-9][0-9]*)\.(0|[1-9][0-9]*)$`)
index 23e0dee1d2f28c302c0367e102495f708dcf95f3..c269d6b6e4e6ffaafd1fba7cc20cd7b5d1a7fd40 100644 (file)
@@ -278,7 +278,7 @@ var depsRules = `
        math/big, go/token
        < go/constant;
 
-       container/heap, go/constant, go/parser, internal/types/errors, regexp
+       container/heap, go/constant, go/parser, internal/types/errors, internal/lazyregexp
        < go/types;
 
        FMT, internal/goexperiment
index 3958ec922cb75f6742f839910c266d4e6a82db91..256c3ec05d3f53d5c48428ef69f4ae1a659d9070 100644 (file)
@@ -8,8 +8,8 @@ import (
        "fmt"
        "go/ast"
        "go/token"
+       "internal/lazyregexp"
        . "internal/types/errors"
-       "regexp"
        "strconv"
        "strings"
 )
@@ -80,4 +80,4 @@ func parseGoVersion(s string) (v version, err error) {
 }
 
 // goVersionRx matches a Go version string, e.g. "go1.12".
-var goVersionRx = regexp.MustCompile(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)
+var goVersionRx = lazyregexp.New(`^go([1-9]\d*)\.(0|[1-9]\d*)$`)