]> Cypherpunks repositories - gostls13.git/commitdiff
internal/sysinfo: use strings.Cut in osCpuInfoName
authorTobias Klauser <tklauser@distanz.ch>
Tue, 7 May 2024 09:05:08 +0000 (11:05 +0200)
committerGopher Robot <gobot@golang.org>
Tue, 7 May 2024 18:42:00 +0000 (18:42 +0000)
Change-Id: I78a6189f0fc5d52b5f88cc0db0d3dbc36f94f826
Reviewed-on: https://go-review.googlesource.com/c/go/+/583715
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/sysinfo/cpuinfo_linux.go

index aff63b33b41a1558cb60ba1190b2171e8e0c8885..24f0a878758f6dae18d25a017778ace69b90d5b1 100644 (file)
@@ -40,17 +40,15 @@ func osCpuInfoName() string {
 
        scanner := bufio.NewScanner(bytes.NewReader(buf))
        for scanner.Scan() {
-               line := scanner.Text()
-               if !strings.Contains(line, ":") {
+               key, value, found := strings.Cut(scanner.Text(), ": ")
+               if !found {
                        continue
                }
-
-               field := strings.SplitN(line, ": ", 2)
-               switch strings.TrimSpace(field[0]) {
+               switch strings.TrimSpace(key) {
                case "Model Name", "model name":
-                       modelName = field[1]
+                       modelName = value
                case "CPU MHz", "cpu MHz":
-                       cpuMHz = field[1]
+                       cpuMHz = value
                }
        }