github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/pools/strings_builder.go (about)

     1  package pools
     2  
     3  import (
     4  	"strings"
     5  	"sync"
     6  )
     7  
     8  /*
     9     Creation Time: 2020 - May - 06
    10     Created by:  (ehsan)
    11     Maintainers:
    12        1.  Ehsan N. Moosa (E2)
    13     Auditor: Ehsan N. Moosa (E2)
    14     Copyright Ronak Software Group 2020
    15  */
    16  
    17  var stringsBuilderPool sync.Pool
    18  
    19  func AcquireStringsBuilder() *strings.Builder {
    20  	sb := stringsBuilderPool.Get()
    21  	if sb == nil {
    22  		return &strings.Builder{}
    23  	}
    24  
    25  	return sb.(*strings.Builder)
    26  }
    27  
    28  func ReleaseStringsBuilder(sb *strings.Builder) {
    29  	sb.Reset()
    30  	stringsBuilderPool.Put(sb)
    31  }