MCPcopy
hub / github.com/gin-gonic/gin / bufApp

Function bufApp

path.go:128–151  ·  view source on GitHub ↗

Internal helper to lazily create a buffer if necessary. Calls to this function get inlined.

(buf *[]byte, s string, w int, c byte)

Source from the content-addressed store, hash-verified

126// Internal helper to lazily create a buffer if necessary.
127// Calls to this function get inlined.
128func 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/"

Callers 2

cleanPathFunction · 0.85
removeRepeatedCharFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected