mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Optimized hexbyte2int
This commit is contained in:
+17
-10
@@ -195,17 +195,24 @@ func hexCharUpper(c byte) byte {
|
||||
return c - 10 + 'A'
|
||||
}
|
||||
|
||||
var hex2intTable = func() []byte {
|
||||
b := make([]byte, 255)
|
||||
for i := byte(0); i < 255; i++ {
|
||||
c := byte(0)
|
||||
if i >= '0' && i <= '9' {
|
||||
c = 1 + i - '0'
|
||||
} else if i >= 'a' && i <= 'f' {
|
||||
c = 1 + i - 'a' + 10
|
||||
} else if i >= 'A' && i <= 'F' {
|
||||
c = 1 + i - 'A' + 10
|
||||
}
|
||||
b[i] = c
|
||||
}
|
||||
return b
|
||||
}()
|
||||
|
||||
func hexbyte2int(c byte) int {
|
||||
if c >= '0' && c <= '9' {
|
||||
return int(c - '0')
|
||||
}
|
||||
if c >= 'a' && c <= 'f' {
|
||||
return int(c - 'a' + 10)
|
||||
}
|
||||
if c >= 'A' && c <= 'F' {
|
||||
return int(c - 'A' + 10)
|
||||
}
|
||||
return -1
|
||||
return int(hex2intTable[c]) - 1
|
||||
}
|
||||
|
||||
const toLower = 'a' - 'A'
|
||||
|
||||
Reference in New Issue
Block a user