Skip to content

Commit 69c95ce

Browse files
committed
Speedup Dict.mapValues by 15%
1 parent a89c034 commit 69c95ce

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/es6/Stdlib_Dict.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function forEachWithKey(dict, f) {
1515

1616
function mapValues(dict, f) {
1717
let target = {};
18-
forEachWithKey(dict, (value, key) => {
18+
Object.keys(dict).forEach(key => {
19+
let value = dict[key];
1920
target[key] = f(value);
2021
});
2122
return target;

lib/js/Stdlib_Dict.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function forEachWithKey(dict, f) {
1515

1616
function mapValues(dict, f) {
1717
let target = {};
18-
forEachWithKey(dict, (value, key) => {
18+
Object.keys(dict).forEach(key => {
19+
let value = dict[key];
1920
target[key] = f(value);
2021
});
2122
return target;

runtime/Stdlib_Dict.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ let forEach = (dict, f) => {
2828
dict->valuesToArray->Stdlib_Array.forEach(value => f(value))
2929
}
3030

31+
@inline
3132
let forEachWithKey = (dict, f) => {
3233
dict->keysToArray->Stdlib_Array.forEach(key => f(dict->getUnsafe(key), key))
3334
}

0 commit comments

Comments
 (0)