You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.go 539B

12345678910111213141516171819202122232425
  1. // Copyright 2015 Huan Du. All rights reserved.
  2. // Licensed under the MIT license that can be found in the LICENSE file.
  3. package xstrings
  4. import (
  5. "bytes"
  6. )
  7. const bufferMaxInitGrowSize = 2048
  8. // Lazy initialize a buffer.
  9. func allocBuffer(orig, cur string) *bytes.Buffer {
  10. output := &bytes.Buffer{}
  11. maxSize := len(orig) * 4
  12. // Avoid to reserve too much memory at once.
  13. if maxSize > bufferMaxInitGrowSize {
  14. maxSize = bufferMaxInitGrowSize
  15. }
  16. output.Grow(maxSize)
  17. output.WriteString(orig[:len(orig)-len(cur)])
  18. return output
  19. }