fix(collection): preserve maps for non-finite upper bounds · openclaw/openclaw@6e25112
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,39 @@ describe("pruneMapToMaxSize", () => {
|
34 | 34 | maxSize: -4, |
35 | 35 | expected: [], |
36 | 36 | }, |
| 37 | +{ |
| 38 | +name: "leaves maps untouched for NaN limits", |
| 39 | +entries: [ |
| 40 | +["a", 1], |
| 41 | +["b", 2], |
| 42 | +] as const, |
| 43 | +maxSize: Number.NaN, |
| 44 | +expected: [ |
| 45 | +["a", 1], |
| 46 | +["b", 2], |
| 47 | +], |
| 48 | +}, |
| 49 | +{ |
| 50 | +name: "leaves maps untouched for positive infinity limits", |
| 51 | +entries: [ |
| 52 | +["a", 1], |
| 53 | +["b", 2], |
| 54 | +] as const, |
| 55 | +maxSize: Number.POSITIVE_INFINITY, |
| 56 | +expected: [ |
| 57 | +["a", 1], |
| 58 | +["b", 2], |
| 59 | +], |
| 60 | +}, |
| 61 | +{ |
| 62 | +name: "clears maps for negative infinity limits", |
| 63 | +entries: [ |
| 64 | +["a", 1], |
| 65 | +["b", 2], |
| 66 | +] as const, |
| 67 | +maxSize: Number.NEGATIVE_INFINITY, |
| 68 | +expected: [], |
| 69 | +}, |
37 | 70 | { |
38 | 71 | name: "leaves undersized maps untouched", |
39 | 72 | entries: [["a", 1]] as const, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | export function pruneMapToMaxSize<K, V>(map: Map<K, V>, maxSize: number): void { |
| 2 | +if (Number.isNaN(maxSize) || maxSize === Number.POSITIVE_INFINITY) { |
| 3 | +return; |
| 4 | +} |
2 | 5 | const limit = Math.max(0, Math.floor(maxSize)); |
3 | 6 | if (limit <= 0) { |
4 | 7 | map.clear(); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。