GeezerVison is showing github.com — stream: keep long-lived stream/iter objects in fast mode · nodejs/node@a203221
File treeExpand file treeCollapse file tree Open diff view settings lib/internal/streams/iter
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/iter/broadcast.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -225,8 +225,7 @@ class BroadcastImpl { | 225 | 225 | return { | 226 | 226 | __proto__: null, | 227 | 227 | [SymbolAsyncIterator]() { | 228 | | - return { | 229 | | - __proto__: null, | | 228 | + return ObjectSetPrototypeOf({ | 230 | 229 | next() { | 231 | 230 | if (state.detached) { | 232 | 231 | if (state.error !== kNoBroadcastError) { | @@ -284,7 +283,7 @@ class BroadcastImpl { | 284 | 283 | detach(); | 285 | 284 | return kDone; | 286 | 285 | }, | 287 | | - }; | | 286 | + }, null); | 288 | 287 | }, | 289 | 288 | }; | 290 | 289 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/iter/from.js +7-9Lines changed: 7 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ const { | 15 | 15 | DataViewPrototypeGetByteLength, | 16 | 16 | DataViewPrototypeGetByteOffset, | 17 | 17 | FunctionPrototypeCall, | | 18 | + ObjectSetPrototypeOf, | 18 | 19 | PromisePrototypeThen, | 19 | 20 | PromiseResolve, | 20 | 21 | PromiseWithResolvers, | @@ -68,13 +69,12 @@ const kNormalizationCancelled = Symbol('kNormalizationCancelled'); | 68 | 69 | const kFlushBatch = Symbol('kFlushBatch'); | 69 | 70 |
| 70 | 71 | function createNormalizationContext() { | 71 | | - return { | 72 | | - __proto__: null, | | 72 | + return ObjectSetPrototypeOf({ | 73 | 73 | cancelled: false, | 74 | 74 | reason: undefined, | 75 | 75 | resolve: null, | 76 | 76 | suppressCleanup: false, | 77 | | - }; | | 77 | + }, null); | 78 | 78 | } | 79 | 79 |
| 80 | 80 | function cancelNormalization(context, reason, suppressCleanup = false) { | @@ -112,8 +112,7 @@ async function waitForNormalization(value, context) { | 112 | 112 | function createNormalizationIterator(createIterator) { | 113 | 113 | const context = createNormalizationContext(); | 114 | 114 | const iterator = createIterator(context); | 115 | | - return { | 116 | | - __proto__: null, | | 115 | + return ObjectSetPrototypeOf({ | 117 | 116 | next(value) { | 118 | 117 | return FunctionPrototypeCall(iterator.next, iterator, value); | 119 | 118 | }, | @@ -129,7 +128,7 @@ function createNormalizationIterator(createIterator) { | 129 | 128 | [SymbolAsyncIterator]() { | 130 | 129 | return this; | 131 | 130 | }, | 132 | | - }; | | 131 | + }, null); | 133 | 132 | } | 134 | 133 |
| 135 | 134 | function createNormalizationSource(createIterator) { | @@ -386,8 +385,7 @@ function yieldNormalizationAbortable(source, context) { | 386 | 385 | } | 387 | 386 | } | 388 | 387 |
| 389 | | - return { | 390 | | - __proto__: null, | | 388 | + return ObjectSetPrototypeOf({ | 391 | 389 | async next() { | 392 | 390 | if (completed) { | 393 | 391 | return { __proto__: null, done: true, value: undefined }; | @@ -433,7 +431,7 @@ function yieldNormalizationAbortable(source, context) { | 433 | 431 | [SymbolAsyncIterator]() { | 434 | 432 | return this; | 435 | 433 | }, | 436 | | - }; | | 434 | + }, null); | 437 | 435 | }, | 438 | 436 | }; | 439 | 437 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/iter/pull.js +7-9Lines changed: 7 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ const { | 11 | 11 | ArrayPrototypePush, | 12 | 12 | ArrayPrototypeSlice, | 13 | 13 | FunctionPrototypeCall, | | 14 | + ObjectSetPrototypeOf, | 14 | 15 | PromisePrototypeThen, | 15 | 16 | PromiseReject, | 16 | 17 | PromiseResolve, | @@ -861,8 +862,7 @@ function pull(source, ...args) { | 861 | 862 | yield* createAsyncPipeline(normalized, transforms, controller.signal); | 862 | 863 | } | 863 | 864 | const iterator = pipeline(); | 864 | | - return { | 865 | | - __proto__: null, | | 865 | + return ObjectSetPrototypeOf({ | 866 | 866 | next(value) { | 867 | 867 | return iterator.next(value); | 868 | 868 | }, | @@ -877,7 +877,7 @@ function pull(source, ...args) { | 877 | 877 | [SymbolAsyncIterator]() { | 878 | 878 | return this; | 879 | 879 | }, | 880 | | - }; | | 880 | + }, null); | 881 | 881 | } | 882 | 882 | return createAbortablePullIterator(normalized, transforms, signal); | 883 | 883 | }, | @@ -907,8 +907,7 @@ function createAbortablePullIterator(source, transforms, signal) { | 907 | 907 | throw error; | 908 | 908 | } | 909 | 909 |
| 910 | | - return { | 911 | | - __proto__: null, | | 910 | + return ObjectSetPrototypeOf({ | 912 | 911 | next(value) { | 913 | 912 | if (aborted) return PromiseReject(signal.reason); | 914 | 913 | return PromisePrototypeThen(iterator.next(value), undefined, onRejected); | @@ -929,7 +928,7 @@ function createAbortablePullIterator(source, transforms, signal) { | 929 | 928 | [SymbolAsyncIterator]() { | 930 | 929 | return this; | 931 | 930 | }, | 932 | | - }; | | 931 | + }, null); | 933 | 932 | } | 934 | 933 |
| 935 | 934 | // Keep ownership of a bonded consumer outside the transform pipeline so it can | @@ -986,8 +985,7 @@ function pullWithConsumerCleanup(source, transforms, signal) { | 986 | 985 | __proto__: null, | 987 | 986 | [SymbolAsyncIterator]() { | 988 | 987 | const iterator = pipeline[SymbolAsyncIterator](); | 989 | | - return { | 990 | | - __proto__: null, | | 988 | + return ObjectSetPrototypeOf({ | 991 | 989 | next(value) { | 992 | 990 | return PromisePrototypeThen( | 993 | 991 | iterator.next(value), | @@ -1011,7 +1009,7 @@ function pullWithConsumerCleanup(source, transforms, signal) { | 1011 | 1009 | [SymbolAsyncIterator]() { | 1012 | 1010 | return this; | 1013 | 1011 | }, | 1014 | | - }; | | 1012 | + }, null); | 1015 | 1013 | }, | 1016 | 1014 | }; | 1017 | 1015 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/iter/push.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | const { | 9 | 9 | ArrayPrototypePush, | | 10 | + ObjectSetPrototypeOf, | 10 | 11 | PromisePrototypeThen, | 11 | 12 | PromiseReject, | 12 | 13 | PromiseResolve, | @@ -733,8 +734,7 @@ function createReadable(queue) { | 733 | 734 | return { | 734 | 735 | __proto__: null, | 735 | 736 | [SymbolAsyncIterator]() { | 736 | | - return { | 737 | | - __proto__: null, | | 737 | + return ObjectSetPrototypeOf({ | 738 | 738 | async next() { | 739 | 739 | return queue.read(); | 740 | 740 | }, | @@ -746,7 +746,7 @@ function createReadable(queue) { | 746 | 746 | queue.consumerThrow(error); | 747 | 747 | throw error; | 748 | 748 | }, | 749 | | - }; | | 749 | + }, null); | 750 | 750 | }, | 751 | 751 | }; | 752 | 752 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/iter/share.js +6-9Lines changed: 6 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,8 +235,7 @@ class ShareImpl { | 235 | 235 | } | 236 | 236 | }; | 237 | 237 |
| 238 | | - return { | 239 | | - __proto__: null, | | 238 | + return ObjectSetPrototypeOf({ | 240 | 239 | next() { | 241 | 240 | const next = PromisePrototypeThen( | 242 | 241 | state.pendingNext, | @@ -266,7 +265,7 @@ class ShareImpl { | 266 | 265 | } | 267 | 266 | return { __proto__: null, done: true, value: undefined }; | 268 | 267 | }, | 269 | | - }; | | 268 | + }, null); | 270 | 269 | }, | 271 | 270 | }; | 272 | 271 | } | @@ -401,16 +400,15 @@ class ShareImpl { | 401 | 400 | } else if (isSyncIterable(this.#source)) { | 402 | 401 | const syncIterator = | 403 | 402 | this.#source[SymbolIterator](); | 404 | | - this.#sourceIterator = { | 405 | | - __proto__: null, | | 403 | + this.#sourceIterator = ObjectSetPrototypeOf({ | 406 | 404 | async next() { | 407 | 405 | return syncIterator.next(); | 408 | 406 | }, | 409 | 407 | async return() { | 410 | 408 | return syncIterator.return?.() ?? | 411 | 409 | { __proto__: null, done: true, value: undefined }; | 412 | 410 | }, | 413 | | - }; | | 411 | + }, null); | 414 | 412 | } else { | 415 | 413 | throw new ERR_INVALID_ARG_TYPE( | 416 | 414 | 'source', ['AsyncIterable', 'Iterable'], this.#source); | @@ -592,8 +590,7 @@ class SyncShareImpl { | 592 | 590 | return { | 593 | 591 | __proto__: null, | 594 | 592 | [SymbolIterator]() { | 595 | | - return { | 596 | | - __proto__: null, | | 593 | + return ObjectSetPrototypeOf({ | 597 | 594 | next() { | 598 | 595 | if (state.detached) { | 599 | 596 | if (state.error !== kNoShareError) throw state.error; | @@ -710,7 +707,7 @@ class SyncShareImpl { | 710 | 707 | } | 711 | 708 | return { __proto__: null, done: true, value: undefined }; | 712 | 709 | }, | 713 | | - }; | | 710 | + }, null); | 714 | 711 | }, | 715 | 712 | }; | 716 | 713 | } | |
|