MCPcopy Index your code
hub / github.com/maruel/panicparse / atou

Function atou

stack/context.go:1162–1174  ·  view source on GitHub ↗

atou is a fast Atoi() function. It is a very simplified version of strconv.Atoi() that it never go into the slow path and it operates on []byte instead of string so it doesn't do memory allocation. It will fail on edge cases like prefix of zeros and other things that the panic stack trace generator

(s []byte)

Source from the content-addressed store, hash-verified

1160//
1161// It doesn't handle negative values.
1162func atou(s []byte) (int, bool) {
1163 if l := len(s); strconv.IntSize == 32 && (0 < l && l < 10) || strconv.IntSize == 64 && (0 < l && l < 19) {
1164 n := 0
1165 for _, ch := range s {
1166 if ch -= '0'; ch > 9 {
1167 return 0, false
1168 }
1169 n = n*10 + int(ch)
1170 }
1171 return n, true
1172 }
1173 return 0, false
1174}
1175
1176// trimLeftSpace is the faster equivalent of bytes.TrimLeft(s, "\t ").
1177func trimLeftSpace(s []byte) []byte {

Callers 3

TestAtouFunction · 0.85
scanMethod · 0.85
parseFileFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestAtouFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…