decodeString converts s to []rune for the MatchString startAt<=0 path. Keep this as close as possible to a single UTF-8 walk so 4–30 byte matches stay cheap.
(s string, maxCachedLength int)
| 59 | // Keep this as close as possible to a single UTF-8 walk so 4–30 byte |
| 60 | // matches stay cheap. |
| 61 | func decodeString(s string, maxCachedLength int) ([]rune, *[]rune) { |
| 62 | buf, pooled := pooledRuneBuffers.get(len(s), maxCachedLength) |
| 63 | if len(s) >= helpers.ASCIIScanMin { |
| 64 | n, _ := helpers.DecodeString(s, buf) |
| 65 | return buf[:n], pooled |
| 66 | } |
| 67 | n := 0 |
| 68 | for _, ch := range s { |
| 69 | buf[n] = ch |
| 70 | n++ |
| 71 | } |
| 72 | return buf[:n], pooled |
| 73 | } |
| 74 | |
| 75 | // decodeStringInput decodes into exact-size storage a returned match can own. |
| 76 | func (re *Regexp) decodeStringInput(s string, startAt int, pooled bool) decodedInput { |
no test coverage detected