Skip to content

Commit

Permalink
Small performance improvements (#2044)
Browse files Browse the repository at this point in the history
* perf: improve null and undefined checks

* perf: improve formdata delete operation
  • Loading branch information
anonrig committed Apr 4, 2023
1 parent 3d21d22 commit 5f3b8e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 1 addition & 8 deletions lib/fetch/formdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,7 @@ class FormData {

// The delete(name) method steps are to remove all entries whose name
// is name from this’s entry list.
const next = []
for (const entry of this[kState]) {
if (entry.name !== name) {
next.push(entry)
}
}

this[kState] = next
this[kState] = this[kState].filter(entry => entry.name !== name)
}

get (name) {
Expand Down
6 changes: 3 additions & 3 deletions lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Request {
}

// 10. If init["window"] exists and is non-null, then throw a TypeError.
if (init.window !== undefined && init.window != null) {
if (init.window != null) {
throw new TypeError(`'window' option '${window}' must be null`)
}

Expand Down Expand Up @@ -427,7 +427,7 @@ class Request {
// non-null, and request’s method is `GET` or `HEAD`, then throw a
// TypeError.
if (
((init.body !== undefined && init.body != null) || inputBody != null) &&
(init.body != null || inputBody != null) &&
(request.method === 'GET' || request.method === 'HEAD')
) {
throw new TypeError('Request with GET/HEAD method cannot have body.')
Expand All @@ -437,7 +437,7 @@ class Request {
let initBody = null

// 36. If init["body"] exists and is non-null, then:
if (init.body !== undefined && init.body != null) {
if (init.body != null) {
// 1. Let Content-Type be null.
// 2. Set initBody and Content-Type to the result of extracting
// init["body"], with keepalive set to request’s keepalive.
Expand Down

0 comments on commit 5f3b8e1

Please sign in to comment.