Skip to content

Commit 0f1f1e4

Browse files
avoid unnecessary array operations
1 parent b146e7d commit 0f1f1e4

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

lib/repl.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,8 @@ function complete(line, callback) {
16431643
}
16441644
}
16451645

1646-
function includesProxiesOrGetters(exprSegments, evalFn, context, callback, currentExpr = '') {
1647-
const currentSegment = exprSegments[0];
1648-
const remainingSegments = ArrayPrototypeSlice(exprSegments, 1);
1646+
function includesProxiesOrGetters(exprSegments, evalFn, context, callback, currentExpr = '', idx = 0) {
1647+
const currentSegment = exprSegments[idx];
16491648
currentExpr += `${currentExpr.length === 0 ? '' : '.'}${currentSegment}`;
16501649
evalFn(`try { ${currentExpr} } catch { }`, context, getREPLResourceName(), (_, currentObj) => {
16511650
if (typeof currentObj !== 'object' || currentObj === null) {
@@ -1656,17 +1655,19 @@ function includesProxiesOrGetters(exprSegments, evalFn, context, callback, curre
16561655
return callback(true);
16571656
}
16581657

1659-
if (remainingSegments.length === 0) {
1658+
const nextIdx = idx + 1;
1659+
1660+
if (nextIdx >= exprSegments.length) {
16601661
return callback(false);
16611662
}
16621663

1663-
const nextSegmentProp = ObjectGetOwnPropertyDescriptor(currentObj, remainingSegments[0]);
1664+
const nextSegmentProp = ObjectGetOwnPropertyDescriptor(currentObj, exprSegments[nextIdx]);
16641665
const nextSegmentPropHasGetter = typeof nextSegmentProp?.get === 'function';
16651666
if (nextSegmentPropHasGetter) {
16661667
return callback(true);
16671668
}
16681669

1669-
return includesProxiesOrGetters(remainingSegments, evalFn, context, callback, currentExpr);
1670+
return includesProxiesOrGetters(exprSegments, evalFn, context, callback, currentExpr, nextIdx);
16701671
});
16711672
}
16721673

0 commit comments

Comments
 (0)