Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-02-07 10:05:30 +08:00
parent 82647de886
commit ac184d61fa
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

15
kernel/cache/asset.go vendored
View file

@ -104,19 +104,6 @@ var (
assetsLock = sync.Mutex{}
)
// GetAssets 返回所有资源的副本
func GetAssets() (ret map[string]*Asset) {
assetsLock.Lock()
defer assetsLock.Unlock()
// 指定长度避免分配新内存时扩容和迁移
ret = make(map[string]*Asset, len(assetsCache))
for k, v := range assetsCache {
ret[k] = v
}
return
}
// IterateAssets 遍历所有资源,适合只读场景
func IterateAssets(fn func(path string, asset *Asset) bool) {
assetsLock.Lock()
@ -134,7 +121,7 @@ func FilterAssets(filter func(path string, asset *Asset) bool) (ret map[string]*
assetsLock.Lock()
defer assetsLock.Unlock()
ret = make(map[string]*Asset)
ret = map[string]*Asset{}
for path, asset := range assetsCache {
if filter(path, asset) {
ret[path] = asset