aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/switch.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2022-06-25 11:11:07 -0700
committerKeith Randall <khr@golang.org>2022-08-31 22:08:26 +0000
commit69aed4712d73c9c1b70be3e2e222eb55391e2fb0 (patch)
tree07d66c7c2961f8d328bd6d0ebbda4cad43242763 /test/codegen/switch.go
parentaf7f067e0d7f92bcf4d0938d093725a0ac6366b1 (diff)
downloadgo-69aed4712d73c9c1b70be3e2e222eb55391e2fb0.tar.xz
cmd/compile: use better splitting condition for string binary search
Currently we use a full cmpstring to do the comparison for each split in the binary search for a string switch. Instead, split by comparing a single byte of the input string with a constant. That will give us a much faster split (although it might be not quite as good a split). Fixes #53333 R=go1.20 Change-Id: I28c7209342314f367071e4aa1f2beb6ec9ff7123 Reviewed-on: https://go-review.googlesource.com/c/go/+/414894 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
Diffstat (limited to 'test/codegen/switch.go')
-rw-r--r--test/codegen/switch.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/codegen/switch.go b/test/codegen/switch.go
index af3762869a..c3c24e2e11 100644
--- a/test/codegen/switch.go
+++ b/test/codegen/switch.go
@@ -72,3 +72,30 @@ func length(x string) int {
return len(x)
}
}
+
+// Use single-byte ordered comparisons for binary searching strings.
+// See issue 53333.
+func mimetype(ext string) string {
+ // amd64: `CMPB\s1\(.*\), \$104$`,-`cmpstring`
+ // arm64: `MOVB\s1\(R.*\), R.*$`, `CMPW\s\$104, R.*$`, -`cmpstring`
+ switch ext {
+ // amd64: `CMPL\s\(.*\), \$1836345390$`
+ // arm64: `CMPW\s\$1836345390, R.*$`
+ case ".htm":
+ return "A"
+ // amd64: `CMPL\s\(.*\), \$1953457454$`
+ // arm64: `CMPW\s\$1953457454, R.*$`
+ case ".eot":
+ return "B"
+ // amd64: `CMPL\s\(.*\), \$1735815982$`
+ // arm64: `CMPW\s\$1735815982, R.*$`
+ case ".svg":
+ return "C"
+ // amd64: `CMPL\s\(.*\), \$1718907950$`
+ // arm64: `CMPW\s\$1718907950, R.*$`
+ case ".ttf":
+ return "D"
+ default:
+ return ""
+ }
+}