github.com/cloudwego/frugal@v0.1.15/internal/binary/decoder/bitmap.go (about) 1 /* 2 * Copyright 2022 ByteDance Inc. 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 package decoder 18 19 import ( 20 `sync` 21 22 `github.com/cloudwego/frugal/internal/atm/hir` 23 ) 24 25 const ( 26 MaxField = 65536 27 MaxBitmap = MaxField / 64 28 ) 29 30 var ( 31 bitmapPool sync.Pool 32 ) 33 34 var ( 35 F_newFieldBitmap = hir.RegisterGCall(newFieldBitmap, emu_gcall_newFieldBitmap) 36 F_FieldBitmap_Free = hir.RegisterGCall((*FieldBitmap).Free, emu_gcall_FieldBitmap_Free) 37 ) 38 39 type ( 40 FieldBitmap [MaxBitmap]int64 41 ) 42 43 func newFieldBitmap() *FieldBitmap { 44 if v := bitmapPool.Get(); v != nil { 45 return v.(*FieldBitmap) 46 } else { 47 return new(FieldBitmap) 48 } 49 } 50 51 func (self *FieldBitmap) Free() { 52 bitmapPool.Put(self) 53 } 54 55 func (self *FieldBitmap) Clear() { 56 *self = FieldBitmap{} 57 } 58 59 func (self *FieldBitmap) Append(i int) { 60 if i < MaxField { 61 self[i / 64] |= 1 << (i % 64) 62 } else { 63 panic("field index too large") 64 } 65 }