lib: reduce overhead of blob clone · nodejs/node@b6021ab · GitHub
Skip to content

Commit b6021ab

Browse files
H4adtargos
authored andcommitted
lib: reduce overhead of blob clone
PR-URL: #50110 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent bac872c commit b6021ab

3 files changed

Lines changed: 20 additions & 16 deletions

File tree

benchmark/blob/clone.js

Lines changed: 5 additions & 2 deletions

lib/internal/blob.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88
ObjectDefineProperty,
99
ObjectSetPrototypeOf,
1010
PromiseReject,
11-
ReflectConstruct,
1211
RegExpPrototypeExec,
1312
RegExpPrototypeSymbolReplace,
1413
StringPrototypeToLowerCase,
@@ -200,7 +199,7 @@ class Blob {
200199
const length = this[kLength];
201200
return {
202201
data: { handle, type, length },
203-
deserializeInfo: 'internal/blob:ClonedBlob',
202+
deserializeInfo: 'internal/blob:Blob',
204203
};
205204
}
206205

@@ -397,25 +396,18 @@ class Blob {
397396
}
398397
}
399398

400-
function ClonedBlob() {
401-
return ReflectConstruct(function() {
402-
markTransferMode(this, true, false);
403-
}, [], Blob);
404-
}
405-
ClonedBlob.prototype[kDeserialize] = () => {};
406-
407-
function TransferrableBlob(handle, length, type = '') {
399+
function TransferableBlob(handle, length, type = '') {
408400
markTransferMode(this, true, false);
409401
this[kHandle] = handle;
410402
this[kType] = type;
411403
this[kLength] = length;
412404
}
413405

414-
ObjectSetPrototypeOf(TransferrableBlob.prototype, Blob.prototype);
415-
ObjectSetPrototypeOf(TransferrableBlob, Blob);
406+
ObjectSetPrototypeOf(TransferableBlob.prototype, Blob.prototype);
407+
ObjectSetPrototypeOf(TransferableBlob, Blob);
416408

417409
function createBlob(handle, length, type = '') {
418-
const transferredBlob = new TransferrableBlob(handle, length, type);
410+
const transferredBlob = new TransferableBlob(handle, length, type);
419411

420412
// Fix issues like: https://github.com/nodejs/node/pull/49730#discussion_r1331720053
421413
transferredBlob.constructor = Blob;
@@ -489,7 +481,6 @@ function createBlobFromFilePath(path, options) {
489481

490482
module.exports = {
491483
Blob,
492-
ClonedBlob,
493484
createBlob,
494485
createBlobFromFilePath,
495486
isBlob,

test/parallel/test-blob.js

Lines changed: 10 additions & 0 deletions

0 commit comments

Comments
 (0)