Commit b9bf2f5d authored by Dong-hee Na's avatar Dong-hee Na Committed by Daniel Martí

html/template: micro optimization for isJSType

There is an unnecessary lower operation in isJSType.
Simple logic fix can improve tiny performance.

name        old time/op    new time/op    delta
isJSType-8     152ns ± 0%      58ns ± 7%   -61.82%  (p=0.001 n=6+8)

name        old alloc/op   new alloc/op   delta
isJSType-8     32.0B ± 0%      0.0B       -100.00%  (p=0.000 n=8+8)

name        old allocs/op  new allocs/op  delta
isJSType-8      1.00 ± 0%      0.00       -100.00%  (p=0.000 n=8+8)

Change-Id: I281aadf1677d4377920c9649af206381189a27e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/177118
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
parent 72e71b90
...@@ -383,11 +383,11 @@ func isJSType(mimeType string) bool { ...@@ -383,11 +383,11 @@ func isJSType(mimeType string) bool {
// https://tools.ietf.org/html/rfc7231#section-3.1.1 // https://tools.ietf.org/html/rfc7231#section-3.1.1
// https://tools.ietf.org/html/rfc4329#section-3 // https://tools.ietf.org/html/rfc4329#section-3
// https://www.ietf.org/rfc/rfc4627.txt // https://www.ietf.org/rfc/rfc4627.txt
mimeType = strings.ToLower(mimeType)
// discard parameters // discard parameters
if i := strings.Index(mimeType, ";"); i >= 0 { if i := strings.Index(mimeType, ";"); i >= 0 {
mimeType = mimeType[:i] mimeType = mimeType[:i]
} }
mimeType = strings.ToLower(mimeType)
mimeType = strings.TrimSpace(mimeType) mimeType = strings.TrimSpace(mimeType)
switch mimeType { switch mimeType {
case case
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment