mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 18:38:33 +00:00
perf(ext/web): optimize transferArrayBuffer (#16294)
Avoid copying enqueued data + misc optimizations to skip webidl converter.
This commit is contained in:
parent
046ab7dc8a
commit
6cd9343e8b
3 changed files with 50 additions and 27 deletions
|
@ -60,6 +60,7 @@
|
|||
WeakMapPrototypeSet,
|
||||
} = globalThis.__bootstrap.primordials;
|
||||
const consoleInternal = window.__bootstrap.console;
|
||||
const ops = core.ops;
|
||||
const { AssertionError, assert } = window.__bootstrap.infra;
|
||||
|
||||
/** @template T */
|
||||
|
@ -224,15 +225,9 @@
|
|||
* @returns {ArrayBufferLike}
|
||||
*/
|
||||
function transferArrayBuffer(O) {
|
||||
assert(!isDetachedBuffer(O));
|
||||
const transferredIshVersion = O.slice(0);
|
||||
ObjectDefineProperty(O, "byteLength", {
|
||||
get() {
|
||||
return 0;
|
||||
},
|
||||
});
|
||||
const v = ops.op_transfer_arraybuffer(O);
|
||||
O[isFakeDetached] = true;
|
||||
return transferredIshVersion;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4620,26 +4615,32 @@
|
|||
* @param {UnderlyingSource<R>=} underlyingSource
|
||||
* @param {QueuingStrategy<R>=} strategy
|
||||
*/
|
||||
constructor(underlyingSource = undefined, strategy = {}) {
|
||||
constructor(underlyingSource = undefined, strategy = undefined) {
|
||||
const prefix = "Failed to construct 'ReadableStream'";
|
||||
if (underlyingSource !== undefined) {
|
||||
underlyingSource = webidl.converters.object(underlyingSource, {
|
||||
prefix,
|
||||
context: "Argument 1",
|
||||
});
|
||||
}
|
||||
strategy = webidl.converters.QueuingStrategy(strategy, {
|
||||
prefix,
|
||||
context: "Argument 2",
|
||||
});
|
||||
this[webidl.brand] = webidl.brand;
|
||||
if (underlyingSource === undefined) {
|
||||
} else {
|
||||
underlyingSource = null;
|
||||
}
|
||||
const underlyingSourceDict = webidl.converters.UnderlyingSource(
|
||||
underlyingSource,
|
||||
{ prefix, context: "underlyingSource" },
|
||||
);
|
||||
if (strategy !== undefined) {
|
||||
strategy = webidl.converters.QueuingStrategy(strategy, {
|
||||
prefix,
|
||||
context: "Argument 2",
|
||||
});
|
||||
} else {
|
||||
strategy = {};
|
||||
}
|
||||
this[webidl.brand] = webidl.brand;
|
||||
let underlyingSourceDict = {};
|
||||
if (underlyingSource !== undefined) {
|
||||
underlyingSourceDict = webidl.converters.UnderlyingSource(
|
||||
underlyingSource,
|
||||
{ prefix, context: "underlyingSource" },
|
||||
);
|
||||
}
|
||||
initializeReadableStream(this);
|
||||
if (underlyingSourceDict.type === "bytes") {
|
||||
if (strategy.size !== undefined) {
|
||||
|
@ -4700,13 +4701,17 @@
|
|||
* @param {ReadableStreamGetReaderOptions=} options
|
||||
* @returns {ReadableStreamDefaultReader<R> | ReadableStreamBYOBReader}
|
||||
*/
|
||||
getReader(options = {}) {
|
||||
getReader(options = undefined) {
|
||||
webidl.assertBranded(this, ReadableStreamPrototype);
|
||||
const prefix = "Failed to execute 'getReader' on 'ReadableStream'";
|
||||
options = webidl.converters.ReadableStreamGetReaderOptions(options, {
|
||||
prefix,
|
||||
context: "Argument 1",
|
||||
});
|
||||
if (options !== undefined) {
|
||||
options = webidl.converters.ReadableStreamGetReaderOptions(options, {
|
||||
prefix,
|
||||
context: "Argument 1",
|
||||
});
|
||||
} else {
|
||||
options = {};
|
||||
}
|
||||
if (options.mode === undefined) {
|
||||
return acquireReadableStreamDefaultReader(this);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue