Skip to content

refactor: use includes() instead of indexOf() for boolean checks#260

Closed
Ayoub-Mabrouk wants to merge 1 commit intojshttp:masterfrom
Ayoub-Mabrouk:optimize/use-includes-instead-of-indexof
Closed

refactor: use includes() instead of indexOf() for boolean checks#260
Ayoub-Mabrouk wants to merge 1 commit intojshttp:masterfrom
Ayoub-Mabrouk:optimize/use-includes-instead-of-indexof

Conversation

@Ayoub-Mabrouk
Copy link
Copy Markdown

Replace str.indexOf("%") === -1 with !str.includes("%") in decode function. This improves readability and may have slight performance benefits as includes() is optimized for boolean checks in modern JavaScript engines.

Replace str.indexOf("%") === -1 with !str.includes("%") in decode function.
This improves readability and may have slight performance benefits as includes()
is optimized for boolean checks in modern JavaScript engines.
@blakeembrey
Copy link
Copy Markdown
Member

While this seems true of V8, it looks like Safari results in a perf hit using includes. I'm not sure why, but it's 75% slower than indexOf. Since this library can be used isomorphically I don't think I'll be merging this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants