Created
April 26, 2014 11:32
-
-
Save olekukonko/11317721 to your computer and use it in GitHub Desktop.
strconv.ParseInt Faster Implementation to convert strings to int64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ascii numbers 0-9 | |
const ( | |
ascii_0 = 48 | |
ascii_9 = 57 | |
) | |
// parseInt64 expects decimal positive numbers. We | |
// return -1 to signal error | |
func parseInt64(d []byte) (n int64) { | |
if len(d) == 0 { | |
return -1 | |
} | |
for _, dec := range d { | |
if dec < ascii_0 || dec > ascii_9 { | |
return -1 | |
} | |
n = n*10 + (int64(dec) - ascii_0) | |
} | |
return n | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment