Skip to content

Commit 5f3b8e1

Browse files
authoredApr 4, 2023
Small performance improvements (#2044)
* perf: improve null and undefined checks * perf: improve formdata delete operation
1 parent 3d21d22 commit 5f3b8e1

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed
 

‎lib/fetch/formdata.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,7 @@ class FormData {
6161

6262
// The delete(name) method steps are to remove all entries whose name
6363
// is name from this’s entry list.
64-
const next = []
65-
for (const entry of this[kState]) {
66-
if (entry.name !== name) {
67-
next.push(entry)
68-
}
69-
}
70-
71-
this[kState] = next
64+
this[kState] = this[kState].filter(entry => entry.name !== name)
7265
}
7366

7467
get (name) {

‎lib/fetch/request.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Request {
128128
}
129129

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

@@ -427,7 +427,7 @@ class Request {
427427
// non-null, and request’s method is `GET` or `HEAD`, then throw a
428428
// TypeError.
429429
if (
430-
((init.body !== undefined && init.body != null) || inputBody != null) &&
430+
(init.body != null || inputBody != null) &&
431431
(request.method === 'GET' || request.method === 'HEAD')
432432
) {
433433
throw new TypeError('Request with GET/HEAD method cannot have body.')
@@ -437,7 +437,7 @@ class Request {
437437
let initBody = null
438438

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

0 commit comments

Comments
 (0)
Please sign in to comment.