Skip to content

Commit 70dbed5

Browse files
ronagmetcoder95
authored andcommitted
perf: use FastBuffer (nodejs#1907)
1 parent 4229917 commit 70dbed5

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/client.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const {
6565
kLocalAddress,
6666
kMaxResponseSize
6767
} = require('./core/symbols')
68+
const FastBuffer = Buffer[Symbol.species]
6869

6970
const kClosedResolve = Symbol('kClosedResolve')
7071

@@ -363,8 +364,7 @@ async function lazyllhttp () {
363364
wasm_on_status: (p, at, len) => {
364365
assert.strictEqual(currentParser.ptr, p)
365366
const start = at - currentBufferPtr
366-
const end = start + len
367-
return currentParser.onStatus(currentBufferRef.slice(start, end)) || 0
367+
return currentParser.onStatus(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
368368
},
369369
wasm_on_message_begin: (p) => {
370370
assert.strictEqual(currentParser.ptr, p)
@@ -373,14 +373,12 @@ async function lazyllhttp () {
373373
wasm_on_header_field: (p, at, len) => {
374374
assert.strictEqual(currentParser.ptr, p)
375375
const start = at - currentBufferPtr
376-
const end = start + len
377-
return currentParser.onHeaderField(currentBufferRef.slice(start, end)) || 0
376+
return currentParser.onHeaderField(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
378377
},
379378
wasm_on_header_value: (p, at, len) => {
380379
assert.strictEqual(currentParser.ptr, p)
381380
const start = at - currentBufferPtr
382-
const end = start + len
383-
return currentParser.onHeaderValue(currentBufferRef.slice(start, end)) || 0
381+
return currentParser.onHeaderValue(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
384382
},
385383
wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => {
386384
assert.strictEqual(currentParser.ptr, p)
@@ -389,8 +387,7 @@ async function lazyllhttp () {
389387
wasm_on_body: (p, at, len) => {
390388
assert.strictEqual(currentParser.ptr, p)
391389
const start = at - currentBufferPtr
392-
const end = start + len
393-
return currentParser.onBody(currentBufferRef.slice(start, end)) || 0
390+
return currentParser.onBody(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
394391
},
395392
wasm_on_message_complete: (p) => {
396393
assert.strictEqual(currentParser.ptr, p)

0 commit comments

Comments
 (0)