Skip to content

Commit

Permalink
refactor(codegen): remove onlyFilterScriptExpression fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Apr 1, 2024
1 parent 28c874e commit 93ecef9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 60 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/codegen.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ const tree = {
scope.emit("$..[?(@.baz)]..baz", 0, false);
},
"$..[?( @property === 'get' || @property === 'put' || @property === 'post' )]": function (scope) {
if (scope.path.length < 1) return;
if (!(scope.sandbox.property === 'get' || scope.sandbox.property === 'put' || scope.sandbox.property === 'post')) return;
scope.emit("$..[?( @property === 'get' || @property === 'put' || @property === 'post' )]", 0, false);
},
Expand Down Expand Up @@ -433,6 +434,7 @@ const tree = {
scope.emit("$.bar[?( @property >= 400 )]..foo", 0, false);
},
"$.[?(@.bar)]": function (scope) {
if (scope.path.length < 1) return;
if (!scope.sandbox.value.bar) return;
scope.emit("$.[?(@.bar)]", 0, false);
},
Expand Down Expand Up @@ -843,6 +845,7 @@ const tree = {
scope.emit("$..headers..[?(@.example && @.schema)]", 0, false);
},
"$..[?(@ && @.example)]": function (scope) {
if (scope.path.length < 1) return;
if (!(scope.sandbox.value && scope.sandbox.value.example)) return;
scope.emit("$..[?(@ && @.example)]", 0, false);
},
Expand Down
27 changes: 12 additions & 15 deletions src/codegen/baseline/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,18 @@ export default function baseline(jsonPaths, opts) {
}
}

const branch =
iterator.feedback.minimumDepth !== -1
? [
b.ifStatement(
b.binaryExpression(
iterator.feedback.fixed && iterator.feedback.stateOffset === -1
? '!=='
: '<',
scope.depth,
b.numericLiteral(iterator.feedback.minimumDepth + 1),
),
b.returnStatement(),
),
]
: [];
const branch = [
b.ifStatement(
b.binaryExpression(
iterator.feedback.fixed && iterator.feedback.stateOffset === -1
? '!=='
: '<',
scope.depth,
b.numericLiteral(iterator.feedback.minimumDepth + 1),
),
b.returnStatement(),
),
];

let zone = tree.traversalZones.create();

Expand Down
3 changes: 1 addition & 2 deletions src/codegen/fast-paths/index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import allParents from './all-parents.mjs';
import fixed from './fixed.mjs';
import onlyFilterScriptExpression from './only-filter-script-expression.mjs';
import root from './root.mjs';

export default [root, onlyFilterScriptExpression, fixed, allParents];
export default [root, fixed, allParents];
43 changes: 0 additions & 43 deletions src/codegen/fast-paths/only-filter-script-expression.mjs

This file was deleted.

0 comments on commit 93ecef9

Please sign in to comment.