Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: convert object to params #3302

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,27 +978,27 @@ function writeH1 (client, request) {

/* istanbul ignore else: assertion */
if (!body || bodyLength === 0) {
writeBuffer({ abort, body: null, client, request, socket, contentLength, header, expectsPayload })
writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isBuffer(body)) {
writeBuffer({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isBlobLike(body)) {
if (typeof body.stream === 'function') {
writeIterable({ abort, body: body.stream(), client, request, socket, contentLength, header, expectsPayload })
writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload)
} else {
writeBlob({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload)
}
} else if (util.isStream(body)) {
writeStream({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isIterable(body)) {
writeIterable({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else {
assert(false)
}

return true
}

function writeStream ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
function writeStream (abort, body, client, request, socket, contentLength, header, expectsPayload) {
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined')

let finished = false
Expand Down Expand Up @@ -1101,7 +1101,7 @@ function writeStream ({ abort, body, client, request, socket, contentLength, hea
}
}

function writeBuffer ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
function writeBuffer (abort, body, client, request, socket, contentLength, header, expectsPayload) {
try {
if (!body) {
if (contentLength === 0) {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ function writeBuffer ({ abort, body, client, request, socket, contentLength, hea
}
}

async function writeBlob ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
async function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) {
assert(contentLength === body.size, 'blob body must have content length')

try {
Expand Down Expand Up @@ -1159,7 +1159,7 @@ async function writeBlob ({ abort, body, client, request, socket, contentLength,
}
}

async function writeIterable ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
async function writeIterable (abort, body, client, request, socket, contentLength, header, expectsPayload) {
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined')

let callback = null
Expand Down
78 changes: 38 additions & 40 deletions lib/dispatcher/client-h2.js
metcoder95 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -477,82 +477,80 @@ function writeH2 (client, request) {
function writeBodyH2 () {
/* istanbul ignore else: assertion */
if (!body || contentLength === 0) {
writeBuffer({
writeBuffer(
abort,
stream,
null,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
body: null,
socket: client[kSocket]
})
expectsPayload
)
} else if (util.isBuffer(body)) {
writeBuffer({
writeBuffer(
abort,
stream,
expectsPayload,
client,
request,
client[kSocket],
contentLength,
body,
expectsPayload,
h2stream: stream,
socket: client[kSocket]
})
body
)
} else if (util.isBlobLike(body)) {
if (typeof body.stream === 'function') {
writeIterable({
writeIterable(
abort,
stream,
body.stream(),
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
body: body.stream(),
socket: client[kSocket]
})
expectsPayload
)
} else {
writeBlob({
writeBlob(
abort,
stream,
body,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
socket: client[kSocket]
})
expectsPayload
)
}
} else if (util.isStream(body)) {
writeStream({
writeStream(
abort,
client[kSocket],
expectsPayload,
stream,
body,
client,
request,
contentLength,
expectsPayload,
socket: client[kSocket],
h2stream: stream,
header: ''
})
contentLength
)
} else if (util.isIterable(body)) {
writeIterable({
writeIterable(
abort,
stream,
body,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
header: '',
h2stream: stream,
socket: client[kSocket]
})
expectsPayload
)
} else {
assert(false)
}
}
}

function writeBuffer ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
function writeBuffer (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
try {
if (body != null && util.isBuffer(body)) {
assert(contentLength === body.byteLength, 'buffer body must have content length')
Expand All @@ -575,7 +573,7 @@ function writeBuffer ({ abort, h2stream, body, client, request, socket, contentL
}
}

function writeStream ({ abort, socket, expectsPayload, h2stream, body, client, request, contentLength }) {
function writeStream (abort, socket, expectsPayload, h2stream, body, client, request, contentLength) {
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined')

// For HTTP/2, is enough to pipe the stream
Expand Down Expand Up @@ -606,7 +604,7 @@ function writeStream ({ abort, socket, expectsPayload, h2stream, body, client, r
}
}

async function writeBlob ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
async function writeBlob (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
assert(contentLength === body.size, 'blob body must have content length')

try {
Expand Down Expand Up @@ -634,7 +632,7 @@ async function writeBlob ({ abort, h2stream, body, client, request, socket, cont
}
}

async function writeIterable ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
async function writeIterable (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined')

let callback = null
Expand Down
Loading