Reduce path formatting allocations
This commit is contained in:
@@ -86,7 +86,20 @@ func (p Path) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Include each separator and the extra byte introduced by escaping a token.
|
||||
// Use stack storage for sizing indexes without allocating another string.
|
||||
size := len(p.segments)
|
||||
var indexText [20]byte
|
||||
for _, segment := range p.segments {
|
||||
if segment.kind == pathSegmentIndex {
|
||||
size += len(strconv.AppendInt(indexText[:0], int64(segment.index), 10))
|
||||
} else {
|
||||
size += len(segment.key) + strings.Count(segment.key, "~") + strings.Count(segment.key, "/")
|
||||
}
|
||||
}
|
||||
|
||||
var b strings.Builder
|
||||
b.Grow(size)
|
||||
for _, segment := range p.segments {
|
||||
b.WriteByte('/')
|
||||
if segment.kind == pathSegmentIndex {
|
||||
|
||||
Reference in New Issue
Block a user