diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2017-07-21 16:08:18 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2017-07-21 16:08:21 +0300 |
commit | d257ae60a32c5605ac63b2f4f0f80a0dcffb0719 (patch) | |
tree | 57fb09fe77e486b193ad72ca6766ce37b13be433 /bytesconv.go | |
parent | Issue #278: more optimizations for normalizeHeaderKey (diff) | |
download | fasthttp-d257ae60a32c5605ac63b2f4f0f80a0dcffb0719.tar.gz fasthttp-d257ae60a32c5605ac63b2f4f0f80a0dcffb0719.tar.bz2 fasthttp-d257ae60a32c5605ac63b2f4f0f80a0dcffb0719.zip |
ioptimized decodeArgAppend a bit
Benchmark results on linux/amd64:
name old time/op new time/op delta
ArgsParse-4 72.8ns ± 2% 68.0ns ± 2% -6.59% (p=0.000 n=10+9)
AppendUnquotedArgFastPath-4 20.4ns ± 2% 21.1ns ± 9% ~ (p=0.614 n=8+10)
AppendUnquotedArgSlowPath-4 68.9ns ± 3% 70.4ns ± 6% ~ (p=0.148 n=9+10)
URIParsePath-4 80.9ns ± 2% 78.7ns ± 2% -2.80% (p=0.000 n=10+10)
URIParsePathQueryString-4 88.9ns ± 1% 86.3ns ± 1% -2.90% (p=0.000 n=10+8)
URIParsePathQueryStringHash-4 95.7ns ± 8% 91.0ns ± 1% -4.88% (p=0.000 n=9+10)
URIParseHostname-4 98.6ns ± 1% 95.4ns ± 1% -3.24% (p=0.000 n=10+10)
Diffstat (limited to 'bytesconv.go')
-rw-r--r-- | bytesconv.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/bytesconv.go b/bytesconv.go index 56d6ca2..d92150f 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -265,8 +265,8 @@ func readHexInt(r *bufio.Reader) (int, error) { } return -1, err } - k = hexbyte2int(c) - if k < 0 { + k = int(hex2intTable[c]) + if k == 16 { if i == 0 { return -1, errEmptyHexNum } @@ -324,23 +324,19 @@ func hexCharUpper(c byte) byte { var hex2intTable = func() []byte { b := make([]byte, 255) for i := byte(0); i < 255; i++ { - c := byte(0) + c := byte(16) if i >= '0' && i <= '9' { - c = 1 + i - '0' + c = i - '0' } else if i >= 'a' && i <= 'f' { - c = 1 + i - 'a' + 10 + c = i - 'a' + 10 } else if i >= 'A' && i <= 'F' { - c = 1 + i - 'A' + 10 + c = i - 'A' + 10 } b[i] = c } return b }() -func hexbyte2int(c byte) int { - return int(hex2intTable[c]) - 1 -} - const toLower = 'a' - 'A' var toLowerTable = func() [256]byte { @@ -401,7 +397,7 @@ func s2b(s string) []byte { // // dst may point to src. In this case src will be overwritten. func AppendUnquotedArg(dst, src []byte) []byte { - return decodeArgAppend(dst, src, true) + return decodeArgAppend(dst, src) } // AppendQuotedArg appends url-encoded src to dst and returns appended dst. |