-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[emval] Move lifecycle mangement from JS to C++. #21300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
14c9753
be79be3
7f43b97
72f13f6
2d9f15d
a73a1b8
79adbce
81cac7c
bb2e662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3548,22 +3548,26 @@ addToLibrary({ | |
| #endif | ||
| }, | ||
|
|
||
| // Sentinel for invalid handles; it's intentionally a distinct object so that | ||
| // we can distinguish it from `undefined` as an actual stored value. | ||
| $invalidHandleSentinel: {}, | ||
|
||
| $HandleAllocator__deps: ['$invalidHandleSentinel'], | ||
| $HandleAllocator: class { | ||
| constructor() { | ||
| // TODO(sbc): Use class fields once we allow/enable es2022 in | ||
| // JavaScript input to acorn and closure. | ||
| // Reserve slot 0 so that 0 is always an invalid handle | ||
| this.allocated = [undefined]; | ||
| this.allocated = [invalidHandleSentinel]; | ||
| this.freelist = []; | ||
| } | ||
| get(id) { | ||
| #if ASSERTIONS | ||
| assert(this.allocated[id] !== undefined, `invalid handle: ${id}`); | ||
| assert(this.allocated[id] !== invalidHandleSentinel, `invalid handle: ${id}`); | ||
| #endif | ||
| return this.allocated[id]; | ||
| }; | ||
| has(id) { | ||
| return this.allocated[id] !== undefined; | ||
| return this.allocated[id] !== invalidHandleSentinel; | ||
| }; | ||
| allocate(handle) { | ||
| var id = this.freelist.pop() || this.allocated.length; | ||
|
|
@@ -3572,11 +3576,9 @@ addToLibrary({ | |
| }; | ||
| free(id) { | ||
| #if ASSERTIONS | ||
| assert(this.allocated[id] !== undefined); | ||
| assert(this.allocated[id] !== invalidHandleSentinel); | ||
| #endif | ||
| // Set the slot to `undefined` rather than using `delete` here since | ||
| // apparently arrays with holes in them can be less efficient. | ||
| this.allocated[id] = undefined; | ||
| this.allocated[id] = invalidHandleSentinel; | ||
| this.freelist.push(id); | ||
| }; | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| "a.html": 673, | ||
| "a.html.gz": 431, | ||
| "a.js": 7086, | ||
| "a.js.gz": 3000, | ||
| "a.wasm": 11433, | ||
| "a.wasm.gz": 5725, | ||
| "total": 19192, | ||
| "total_gz": 9156 | ||
| "a.js": 7202, | ||
| "a.js.gz": 3031, | ||
| "a.wasm": 11498, | ||
| "a.wasm.gz": 5766, | ||
| "total": 19373, | ||
| "total_gz": 9228 | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.