From 69aed4712d73c9c1b70be3e2e222eb55391e2fb0 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 25 Jun 2022 11:11:07 -0700 Subject: 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 Run-TryBot: Keith Randall Reviewed-by: David Chase Reviewed-by: Heschi Kreinick --- test/codegen/switch.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/codegen') 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 "" + } +} -- cgit v1.3-5-g9baa