github.com/cloudwego/kitex@v0.9.0/pkg/utils/strbuf.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 //lint:file-ignore SA6002 allocations cannot be avoided 18 19 package utils 20 21 import ( 22 "strconv" 23 "strings" 24 "sync" 25 ) 26 27 var intBytesPool = sync.Pool{ 28 New: func() interface{} { 29 return make([]byte, 0, 20) 30 }, 31 } 32 33 // WriteInt64ToStringBuilder writes a int64 to a strings.Builder. 34 func WriteInt64ToStringBuilder(sb *strings.Builder, value int64) { 35 bs := intBytesPool.Get().([]byte) 36 bs = strconv.AppendInt(bs, value, 10) 37 sb.Write(bs) 38 intBytesPool.Put(bs[:0]) 39 }