github.com/gogf/gf/v2@v2.7.4/util/gconv/internal/structcache/structcache_pool.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package structcache 8 9 import ( 10 "sync" 11 ) 12 13 var ( 14 poolUsedParamsKeyOrTagNameMap = &sync.Pool{ 15 New: func() any { 16 return make(map[string]struct{}) 17 }, 18 } 19 ) 20 21 // GetUsedParamsKeyOrTagNameMapFromPool retrieves and returns a map for storing params key or tag name. 22 func GetUsedParamsKeyOrTagNameMapFromPool() map[string]struct{} { 23 return poolUsedParamsKeyOrTagNameMap.Get().(map[string]struct{}) 24 } 25 26 // PutUsedParamsKeyOrTagNameMapToPool puts a map for storing params key or tag name into pool for re-usage. 27 func PutUsedParamsKeyOrTagNameMapToPool(m map[string]struct{}) { 28 // need to be cleared before putting back into pool. 29 for k := range m { 30 delete(m, k) 31 } 32 poolUsedParamsKeyOrTagNameMap.Put(m) 33 }