Skip to content

Commit ad0a310

Browse files
Merge pull request #20706 from Snuffleupagus/ensureDebugMetadata-getOrInsertComputed
Use `Map.prototype.getOrInsertComputed()` in the `ensureDebugMetadata` helper
2 parents e62a990 + 0d8bc68 commit ad0a310

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

src/display/canvas_dependency_tracker.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/* Copyright 2025 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
import { Util } from "../shared/util.js";
217

318
const FORCED_DEPENDENCY_LABEL = "__forcedDependency";
@@ -50,17 +65,11 @@ class BBoxReader {
5065
}
5166
}
5267

53-
const ensureDebugMetadata = (map, key) => {
54-
if (!map) {
55-
return undefined;
56-
}
57-
let value = map.get(key);
58-
if (!value) {
59-
value = { dependencies: new Set(), isRenderingOperation: false };
60-
map.set(key, value);
61-
}
62-
return value;
63-
};
68+
const ensureDebugMetadata = (map, key) =>
69+
map?.getOrInsertComputed(key, () => ({
70+
dependencies: new Set(),
71+
isRenderingOperation: false,
72+
}));
6473

6574
/**
6675
* @typedef {"lineWidth" | "lineCap" | "lineJoin" | "miterLimit" | "dash" |

0 commit comments

Comments
 (0)