Skip to content

Commit

Permalink
perf: don't read existing values when parsing without array repeat (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
PondWader authored Jun 23, 2024
1 parent 036311a commit b7a909e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ export function parse(input: string, options?: ParseOptions): ParsedQuery {
}

const newValue = valueDeserializer(value, currentKey);
const currentValue = currentObj[currentKey];

if (currentValue === undefined || !arrayRepeat) {
currentObj[currentKey] = newValue;
} else if (arrayRepeat) {
if (arrayRepeat) {
const currentValue = currentObj[currentKey];
if (currentValue === undefined) {
currentObj[currentKey] = newValue;
}
// Optimization: value.pop is faster than Array.isArray(value)
if ((currentValue as unknown[]).pop) {
else if ((currentValue as unknown[]).pop) {
(currentValue as unknown[]).push(newValue);
} else {
currentObj[currentKey] = [currentValue, newValue];
}
}
} else currentObj[currentKey] = newValue;
}

// Reset reading key value pairs
Expand Down

0 comments on commit b7a909e

Please sign in to comment.