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)
| 1160 | // |
| 1161 | // It doesn't handle negative values. |
| 1162 | func 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 "). |
| 1177 | func trimLeftSpace(s []byte) []byte { |