Skip to content

Commit

Permalink
perf: avoid deoptimization on out of bounds (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Sep 5, 2022
1 parent 1544f13 commit c9d079f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ function parse(input) {
let equalityIndex = -1;
let shouldDecode = false;
let hasPlus = false;
const lastIndex = input.length;

// Have a boundary of input.length + 1 to access last pair inside the loop.
for (let i = 0; i < input.length + 1; i++) {
let c = input.charCodeAt(i);
for (let i = 0; i < lastIndex + 1; i++) {
let c = (i !== lastIndex && input.charCodeAt(i)) || 0;

// Handle '&' and end of line to pass the current values to result
if (c === 38 || isNaN(c)) {
if (c === 38 || c === 0) {
// Check if the current range consist of a single key
if (equalityIndex <= startingIndex) {
key = input.slice(startingIndex + 1, i);
Expand Down

0 comments on commit c9d079f

Please sign in to comment.