mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 14:24:30 +00:00
refactor(core): dedupe shared config and runtime helpers
This commit is contained in:
15
src/infra/map-size.ts
Normal file
15
src/infra/map-size.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function pruneMapToMaxSize<K, V>(map: Map<K, V>, maxSize: number): void {
|
||||
const limit = Math.max(0, Math.floor(maxSize));
|
||||
if (limit <= 0) {
|
||||
map.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
while (map.size > limit) {
|
||||
const oldest = map.keys().next();
|
||||
if (oldest.done) {
|
||||
break;
|
||||
}
|
||||
map.delete(oldest.value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user