Skip to content

Instantly share code, notes, and snippets.

@olekukonko
Created April 26, 2014 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olekukonko/11317721 to your computer and use it in GitHub Desktop.
Save olekukonko/11317721 to your computer and use it in GitHub Desktop.
strconv.ParseInt Faster Implementation to convert strings to int64
// 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