1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00
task/vendor/github.com/huandu/xstrings/common.go

26 lines
539 B
Go
Raw Normal View History

2017-06-04 21:06:04 +02:00
// Copyright 2015 Huan Du. All rights reserved.
// Licensed under the MIT license that can be found in the LICENSE file.
package xstrings
import (
"bytes"
)
2018-03-04 00:28:08 +02:00
const bufferMaxInitGrowSize = 2048
2017-06-04 21:06:04 +02:00
// Lazy initialize a buffer.
func allocBuffer(orig, cur string) *bytes.Buffer {
output := &bytes.Buffer{}
maxSize := len(orig) * 4
// Avoid to reserve too much memory at once.
2018-03-04 00:28:08 +02:00
if maxSize > bufferMaxInitGrowSize {
maxSize = bufferMaxInitGrowSize
2017-06-04 21:06:04 +02:00
}
output.Grow(maxSize)
output.WriteString(orig[:len(orig)-len(cur)])
return output
}