Internal helper to lazily create a buffer if necessary. Calls to this function get inlined.
(buf *[]byte, s string, w int, c byte)
| 126 | // Internal helper to lazily create a buffer if necessary. |
| 127 | // Calls to this function get inlined. |
| 128 | func bufApp(buf *[]byte, s string, w int, c byte) { |
| 129 | b := *buf |
| 130 | if len(b) == 0 { |
| 131 | // No modification of the original string so far. |
| 132 | // If the next character is the same as in the original string, we do |
| 133 | // not yet have to allocate a buffer. |
| 134 | if s[w] == c { |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | // Otherwise use either the stack buffer, if it is large enough, or |
| 139 | // allocate a new buffer on the heap, and copy all previous characters. |
| 140 | length := len(s) |
| 141 | if length > cap(b) { |
| 142 | *buf = make([]byte, length) |
| 143 | } else { |
| 144 | *buf = (*buf)[:length] |
| 145 | } |
| 146 | b = *buf |
| 147 | |
| 148 | copy(b, s[:w]) |
| 149 | } |
| 150 | b[w] = c |
| 151 | } |
| 152 | |
| 153 | // removeRepeatedChar removes multiple consecutive 'char's from a string. |
| 154 | // if s == "/a//b///c////" && char == '/', it returns "/a/b/c/" |
no outgoing calls
no test coverage detected