Skip to content

Commit

Permalink
Sped up the key processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed Dec 22, 2024
1 parent 53143bb commit fc7242c
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/filters/filter-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const regExpFilter = (regExp, separator) => {
};

const filterBase =
({specialAction = 'accept', defaultAction = 'ignore', nonCheckableAction = 'ignore', transition} = {}) =>
({specialAction = 'accept', defaultAction = 'ignore', nonCheckableAction = 'process-key', transition} = {}) =>
options => {
const once = options?.once,
separator = options?.pathSeparator || '.';
Expand Down Expand Up @@ -70,20 +70,35 @@ const filterBase =
// process the optional value token (unfinished)
if (optionalToken) {
if (optionalToken === chunk.name) {
const returnToken = state === 'accept-value' ? chunk : none;
let returnToken = none;
switch (state) {
case 'accept-value':
returnToken = chunk;
state = once ? 'pass' : 'check';
break;
case 'process-key':
stack[stack.length - 1] = chunk.value;
state = 'check';
break;
default:
state = once ? 'pass' : 'check';
break;
}
optionalToken = '';
state = once ? 'pass' : 'check';
return returnToken;
}
optionalToken = '';
state = once ? 'pass' : 'check';
state = once && state !== 'process-key' ? 'pass' : 'check';
}

let returnToken = none;

recheck: for (;;) {
// accept/reject tokens
switch (state) {
case 'process-key':
if (chunk.name === 'endKey') optionalToken = 'keyValue';
return none;
case 'pass':
return none;
case 'accept':
Expand Down Expand Up @@ -170,13 +185,17 @@ const filterBase =

endToken = stopTokens[chunk.name] || '';
switch (action) {
case 'process-key':
if (chunk.name === 'startKey') {
state = 'process-key';
continue recheck;
}
break;
case 'accept-token':
if (endToken) {
if (optionalTokens[endToken]) {
state = 'accept-value';
startTransition = !!transition;
continue recheck;
}
if (endToken && optionalTokens[endToken]) {
state = 'accept-value';
startTransition = !!transition;
continue recheck;
}
if (transition) returnToken = transition(stack, chunk, action, sanitizedOptions);
if (returnToken === none) {
Expand Down

0 comments on commit fc7242c

Please sign in to comment.