aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM. J. Fromberger <michael.j.fromberger@gmail.com>2019-05-24 14:45:30 -0700
committerM. J. Fromberger <michael.j.fromberger@gmail.com>2019-05-24 14:58:40 -0700
commit88bb163be48a40dc09119b76758b9b2cc52c0a43 (patch)
tree656f443767cebe170989fb782fd8a43731d6977d
parent98ae5c3e81a509f4f4f67910c7221d5d4a335d96 (diff)
downloadgo-creachadair-shell-88bb163be48a40dc09119b76758b9b2cc52c0a43.tar.gz
Classify bytes with a direct function rather than a map.
BENCHMARK BEFORE AFTER SPEEDUP (%) BenchmarkSplit/len_1-12 637 ns/op 614 ns/op 3.6 BenchmarkSplit/len_4-12 722 ns/op 651 ns/op 9.8 BenchmarkSplit/len_16-12 1027 ns/op 766 ns/op 25 BenchmarkSplit/len_64-12 2240 ns/op 1169 ns/op 47 BenchmarkSplit/len_256-12 7581 ns/op 3075 ns/op 59 BenchmarkSplit/len_1024-12 28900 ns/op 10524 ns/op 65 BenchmarkSplit/len_4096-12 111494 ns/op 40101 ns/op 64 BenchmarkSplit/len_16384-12 443554 ns/op 160389 ns/op 63 BenchmarkSplit/len_65536-12 1839388 ns/op 699041 ns/op 62 BenchmarkSplit/len_100739-12 2852095 ns/op 1093299 ns/op 61
-rw-r--r--shell.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/shell.go b/shell.go
index e244d10..bfb6f8c 100644
--- a/shell.go
+++ b/shell.go
@@ -140,20 +140,21 @@ var update = [...][]struct {
},
}
-var byteClass = map[byte]class{
- ' ': clBreak,
- '\t': clBreak,
- '\n': clNewline,
- '\\': clQuote,
- '\'': clSingle,
- '"': clDouble,
-}
-
func classOf(b byte) class {
- if c, ok := byteClass[b]; ok {
- return c
+ switch b {
+ case ' ', '\t':
+ return clBreak
+ case '\n':
+ return clNewline
+ case '\\':
+ return clQuote
+ case '\'':
+ return clSingle
+ case '"':
+ return clDouble
+ default:
+ return clOther
}
- return clOther
}
// A Scanner partitions input from a reader into tokens divided on space, tab,