diff options
| author | Kenta Moriuchi <moriken@kimamass.com> | 2023-01-06 21:45:23 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-06 21:45:23 +0900 |
| commit | ff89ff4abba39ce158056d390e761495f5a7bc86 (patch) | |
| tree | 03a9c71b5bb3889842db06ed41c3999074c4107a /ext/web | |
| parent | 39cbaa6d34c249afc4b197836da1fa6dd143cbf9 (diff) | |
perf(ext,runtime): remove using `SafeArrayIterator` from `for-of` (#17255)
Diffstat (limited to 'ext/web')
| -rw-r--r-- | ext/web/01_dom_exception.js | 61 | ||||
| -rw-r--r-- | ext/web/01_mimesniff.js | 4 | ||||
| -rw-r--r-- | ext/web/02_event.js | 11 | ||||
| -rw-r--r-- | ext/web/06_streams.js | 26 | ||||
| -rw-r--r-- | ext/web/09_file.js | 19 | ||||
| -rw-r--r-- | ext/web/10_filereader.js | 3 | ||||
| -rw-r--r-- | ext/web/13_message_port.js | 13 |
7 files changed, 75 insertions, 62 deletions
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index 63b82b01f..031558bee 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -19,7 +19,6 @@ ObjectEntries, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, - SafeArrayIterator, Symbol, SymbolFor, } = window.__bootstrap.primordials; @@ -166,37 +165,35 @@ webidl.configurePrototype(DOMException); const DOMExceptionPrototype = DOMException.prototype; - for ( - const [key, value] of new SafeArrayIterator( - ObjectEntries({ - INDEX_SIZE_ERR, - DOMSTRING_SIZE_ERR, - HIERARCHY_REQUEST_ERR, - WRONG_DOCUMENT_ERR, - INVALID_CHARACTER_ERR, - NO_DATA_ALLOWED_ERR, - NO_MODIFICATION_ALLOWED_ERR, - NOT_FOUND_ERR, - NOT_SUPPORTED_ERR, - INUSE_ATTRIBUTE_ERR, - INVALID_STATE_ERR, - SYNTAX_ERR, - INVALID_MODIFICATION_ERR, - NAMESPACE_ERR, - INVALID_ACCESS_ERR, - VALIDATION_ERR, - TYPE_MISMATCH_ERR, - SECURITY_ERR, - NETWORK_ERR, - ABORT_ERR, - URL_MISMATCH_ERR, - QUOTA_EXCEEDED_ERR, - TIMEOUT_ERR, - INVALID_NODE_TYPE_ERR, - DATA_CLONE_ERR, - }), - ) - ) { + const entries = ObjectEntries({ + INDEX_SIZE_ERR, + DOMSTRING_SIZE_ERR, + HIERARCHY_REQUEST_ERR, + WRONG_DOCUMENT_ERR, + INVALID_CHARACTER_ERR, + NO_DATA_ALLOWED_ERR, + NO_MODIFICATION_ALLOWED_ERR, + NOT_FOUND_ERR, + NOT_SUPPORTED_ERR, + INUSE_ATTRIBUTE_ERR, + INVALID_STATE_ERR, + SYNTAX_ERR, + INVALID_MODIFICATION_ERR, + NAMESPACE_ERR, + INVALID_ACCESS_ERR, + VALIDATION_ERR, + TYPE_MISMATCH_ERR, + SECURITY_ERR, + NETWORK_ERR, + ABORT_ERR, + URL_MISMATCH_ERR, + QUOTA_EXCEEDED_ERR, + TIMEOUT_ERR, + INVALID_NODE_TYPE_ERR, + DATA_CLONE_ERR, + }); + for (let i = 0; i < entries.length; ++i) { + const [key, value] = entries[i]; const desc = { value, enumerable: true }; ObjectDefineProperty(DOMException, key, desc); ObjectDefineProperty(DOMException.prototype, key, desc); diff --git a/ext/web/01_mimesniff.js b/ext/web/01_mimesniff.js index f0f02d53a..2d67d5f95 100644 --- a/ext/web/01_mimesniff.js +++ b/ext/web/01_mimesniff.js @@ -16,7 +16,6 @@ MapPrototypeHas, MapPrototypeSet, RegExpPrototypeTest, - SafeArrayIterator, SafeMapIterator, StringPrototypeReplaceAll, StringPrototypeToLowerCase, @@ -223,7 +222,8 @@ let charset = null; let essence_ = null; let mimeType = null; - for (const value of new SafeArrayIterator(headerValues)) { + for (let i = 0; i < headerValues.length; ++i) { + const value = headerValues[i]; const temporaryMimeType = parseMimeType(value); if ( temporaryMimeType === null || diff --git a/ext/web/02_event.js b/ext/web/02_event.js index 3e7a4d108..dac126280 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -428,7 +428,8 @@ Ctor, props, ) { - for (const prop of new SafeArrayIterator(props)) { + for (let i = 0; i < props.length; ++i) { + const prop = props[i]; ReflectDefineProperty(Ctor.prototype, prop, { enumerable: true }); } } @@ -969,7 +970,9 @@ listeners[type] = []; } - for (const listener of new SafeArrayIterator(listeners[type])) { + const listenerList = listeners[type]; + for (let i = 0; i < listenerList.length; ++i) { + const listener = listenerList[i]; if ( ((typeof listener.options === "boolean" && listener.options === options.capture) || @@ -1454,7 +1457,9 @@ colno = jsError.frames[0].columnNumber; } else { const jsError = core.destructureError(new Error()); - for (const frame of new SafeArrayIterator(jsError.frames)) { + const frames = jsError.frames; + for (let i = 0; i < frames.length; ++i) { + const frame = frames[i]; if ( typeof frame.fileName == "string" && !StringPrototypeStartsWith(frame.fileName, "deno:") diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 67fbaa6c9..81d97218a 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -42,7 +42,6 @@ queueMicrotask, RangeError, ReflectHas, - SafeArrayIterator, SafePromiseAll, SharedArrayBuffer, Symbol, @@ -858,10 +857,11 @@ } const finalBuffer = new Uint8Array(totalLength); - let i = 0; - for (const chunk of new SafeArrayIterator(chunks)) { - TypedArrayPrototypeSet(finalBuffer, chunk, i); - i += chunk.byteLength; + let offset = 0; + for (let i = 0; i < chunks.length; ++i) { + const chunk = chunks[i]; + TypedArrayPrototypeSet(finalBuffer, chunk, offset); + offset += chunk.byteLength; } return finalBuffer; } @@ -1346,7 +1346,8 @@ if (reader !== undefined && isReadableStreamBYOBReader(reader)) { const readIntoRequests = reader[_readIntoRequests]; reader[_readIntoRequests] = []; - for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { + for (let i = 0; i < readIntoRequests.length; ++i) { + const readIntoRequest = readIntoRequests[i]; readIntoRequest.closeSteps(undefined); } } @@ -1372,7 +1373,8 @@ /** @type {Array<ReadRequest<R>>} */ const readRequests = reader[_readRequests]; reader[_readRequests] = []; - for (const readRequest of new SafeArrayIterator(readRequests)) { + for (let i = 0; i < readRequests.length; ++i) { + const readRequest = readRequests[i]; readRequest.closeSteps(); } } @@ -1594,7 +1596,8 @@ function readableStreamDefaultReaderErrorReadRequests(reader, e) { const readRequests = reader[_readRequests]; reader[_readRequests] = []; - for (const readRequest of new SafeArrayIterator(readRequests)) { + for (let i = 0; i < readRequests.length; ++i) { + const readRequest = readRequests[i]; readRequest.errorSteps(e); } } @@ -2614,7 +2617,8 @@ function readableStreamBYOBReaderErrorReadIntoRequests(reader, e) { const readIntoRequests = reader[_readIntoRequests]; reader[_readIntoRequests] = []; - for (const readIntoRequest of new SafeArrayIterator(readIntoRequests)) { + for (let i = 0; i < readIntoRequests.length; ++i) { + const readIntoRequest = readIntoRequests[i]; readIntoRequest.errorSteps(e); } } @@ -4238,7 +4242,9 @@ stream[_state] = "errored"; stream[_controller][_errorSteps](); const storedError = stream[_storedError]; - for (const writeRequest of new SafeArrayIterator(stream[_writeRequests])) { + const writeRequests = stream[_writeRequests]; + for (let i = 0; i < writeRequests.length; ++i) { + const writeRequest = writeRequests[i]; writeRequest.reject(storedError); } stream[_writeRequests] = []; diff --git a/ext/web/09_file.js b/ext/web/09_file.js index 92de61e1f..f789a24d2 100644 --- a/ext/web/09_file.js +++ b/ext/web/09_file.js @@ -26,7 +26,6 @@ MathMin, ObjectPrototypeIsPrototypeOf, RegExpPrototypeTest, - SafeArrayIterator, StringPrototypeCharAt, StringPrototypeToLowerCase, StringPrototypeSlice, @@ -95,8 +94,8 @@ /** @param {(BlobReference | Blob)[]} parts */ async function* toIterator(parts) { - for (const part of new SafeArrayIterator(parts)) { - yield* part.stream(); + for (let i = 0; i < parts.length; ++i) { + yield* parts[i].stream(); } } @@ -111,7 +110,8 @@ /** @type {(BlobReference|Blob)[]} */ const processedParts = []; let size = 0; - for (const element of new SafeArrayIterator(parts)) { + for (let i = 0; i < parts.length; ++i) { + const element = parts[i]; if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, element)) { const chunk = new Uint8Array(ArrayBufferPrototypeSlice(element, 0)); ArrayPrototypePush(processedParts, BlobReference.fromUint8Array(chunk)); @@ -159,7 +159,9 @@ * @returns {string[]} */ function getParts(blob, bag = []) { - for (const part of new SafeArrayIterator(blob[_parts])) { + const parts = blob[_parts]; + for (let i = 0; i < parts.length; ++i) { + const part = parts[i]; if (ObjectPrototypeIsPrototypeOf(BlobPrototype, part)) { getParts(part, bag); } else { @@ -276,7 +278,9 @@ const blobParts = []; let added = 0; - for (const part of new SafeArrayIterator(this[_parts])) { + const parts = this[_parts]; + for (let i = 0; i < parts.length; ++i) { + const part = parts[i]; // don't add the overflow to new blobParts if (added >= span) { // Could maybe be possible to remove variable `added` @@ -600,7 +604,8 @@ const parts = []; let totalSize = 0; - for (const { uuid, size } of new SafeArrayIterator(blobData.parts)) { + for (let i = 0; i < blobData.parts.length; ++i) { + const { uuid, size } = blobData.parts[i]; ArrayPrototypePush(parts, new BlobReference(uuid, size)); totalSize += size; } diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index bd5ee85be..fb119f43e 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -158,7 +158,8 @@ ); const bytes = new Uint8Array(size); let offs = 0; - for (const chunk of new SafeArrayIterator(chunks)) { + for (let i = 0; i < chunks.length; ++i) { + const chunk = chunks[i]; TypedArrayPrototypeSet(bytes, chunk, offs); offs += chunk.byteLength; } diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index f589ac91f..8b8aa57ac 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -22,7 +22,6 @@ ArrayPrototypePush, ObjectPrototypeIsPrototypeOf, ObjectSetPrototypeOf, - SafeArrayIterator, Symbol, SymbolFor, SymbolIterator, @@ -205,9 +204,8 @@ const arrayBufferIdsInTransferables = []; const transferredArrayBuffers = []; - for ( - const transferable of new SafeArrayIterator(messageData.transferables) - ) { + for (let i = 0; i < messageData.transferables.length; ++i) { + const transferable = messageData.transferables[i]; switch (transferable.kind) { case "messagePort": { const port = createMessagePort(transferable.data); @@ -217,8 +215,8 @@ } case "arrayBuffer": { ArrayPrototypePush(transferredArrayBuffers, transferable.data); - const i = ArrayPrototypePush(transferables, null); - ArrayPrototypePush(arrayBufferIdsInTransferables, i); + const index = ArrayPrototypePush(transferables, null); + ArrayPrototypePush(arrayBufferIdsInTransferables, index); break; } default: @@ -274,7 +272,8 @@ const serializedTransferables = []; let arrayBufferI = 0; - for (const transferable of new SafeArrayIterator(transferables)) { + for (let i = 0; i < transferables.length; ++i) { + const transferable = transferables[i]; if (ObjectPrototypeIsPrototypeOf(MessagePortPrototype, transferable)) { webidl.assertBranded(transferable, MessagePortPrototype); const id = transferable[_id]; |
