Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const domainValueRegExp =
const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;

const __toString = Object.prototype.toString;
const __hasOwnProperty = Object.prototype.hasOwnProperty;

const NullObject = /* @__PURE__ */ (() => {
const C = function () {};
Expand All @@ -82,7 +81,7 @@ export interface ParseOptions {
*
* @default decodeURIComponent
*/
decode?: (str: string) => string | undefined;
Comment thread
blakeembrey marked this conversation as resolved.
decode?: (str: string) => string;
}

/**
Expand Down Expand Up @@ -121,7 +120,7 @@ export function parse(
const key = str.slice(keyStartIdx, keyEndIdx);

// only assign once
if (!__hasOwnProperty.call(obj, key)) {
if (obj[key] === undefined) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double check performance? I didn’t change this because my numbers were worse doing the undefined check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me bench it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bench LGTM, would you be free to rebase on main and remove the if (value !== undefined) now? Since it won't matter if dec returns undefined from #179.

let valStartIdx = startIndex(str, eqIdx + 1, endIdx);
let valEndIdx = endIndex(str, endIdx, valStartIdx);

Expand All @@ -134,7 +133,8 @@ export function parse(
}

const value = dec(str.slice(valStartIdx, valEndIdx));
if (value !== undefined) obj[key] = value;

obj[key] = value;
}

index = endIdx + 1;
Expand Down Expand Up @@ -366,7 +366,7 @@ export function serialize(
/**
* URL-decode string value. Optimized to skip native call when no %.
*/
function decode(str: string): string | undefined {
function decode(str: string): string {
if (str.indexOf("%") === -1) return str;

try {
Expand Down