Skip to content

Commit 4145618

Browse files
committed
minor performance optimization polyfills of methods from Map upsert proposal
1 parent a4ff448 commit 4145618

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Allow `null` as `optionOrStep`
77
- Improved accuracy of `Math.{ asinh, atanh }` polyfills with big and small values
88
- Improved accuracy of `Number.prototype.toExponential` polyfills with big and small values
9+
- Minor performance optimization of polyfills of methods from [`Map` upsert proposal](https://github.com/tc39/proposal-upsert)
910
- Wrap `Symbol.for` in `Symbol.prototype.description` polyfill for correct handling of empty string descriptions
1011
- Fixed one more case (`Iterator.prototype.take`) of a V8 ~ Chromium < 126 [bug](https://issues.chromium.org/issues/336839115)
1112
- Forced replacement of `Iterator.{ concat, zip, zipKeyed }` in the pure version for ensuring proper wrapped `Iterator` instances as the result

packages/core-js/modules/es.map.get-or-insert-computed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ var set = MapHelpers.set;
1313
// https://github.com/tc39/proposal-upsert
1414
$({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
1515
getOrInsertComputed: function getOrInsertComputed(key, callbackfn) {
16-
aMap(this);
16+
var hasKey = has(IS_PURE ? aMap(this) : this, key);
1717
aCallable(callbackfn);
18-
if (has(this, key)) return get(this, key);
18+
if (hasKey) return get(this, key);
1919
// CanonicalizeKeyedCollectionKey
2020
if (key === 0 && 1 / key === -Infinity) key = 0;
2121
var value = callbackfn(key);

packages/core-js/modules/es.map.get-or-insert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var set = MapHelpers.set;
1212
// https://github.com/tc39/proposal-upsert
1313
$({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
1414
getOrInsert: function getOrInsert(key, value) {
15-
if (has(aMap(this), key)) return get(this, key);
15+
if (has(IS_PURE ? aMap(this) : this, key)) return get(this, key);
1616
set(this, key, value);
1717
return value;
1818
}

packages/core-js/modules/es.weak-map.get-or-insert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var set = WeakMapHelpers.set;
1212
// https://github.com/tc39/proposal-upsert
1313
$({ target: 'WeakMap', proto: true, real: true, forced: IS_PURE }, {
1414
getOrInsert: function getOrInsert(key, value) {
15-
if (has(aWeakMap(this), key)) return get(this, key);
15+
if (has(IS_PURE ? aWeakMap(this) : this, key)) return get(this, key);
1616
set(this, key, value);
1717
return value;
1818
}

0 commit comments

Comments
 (0)