mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-04 08:04:37 +08:00
Untyped functions built each member of an object literal with scr_dyn_key_set: a lookup of the key in the new object, a walk of its empty prototype chain, a second lookup before the append, and a hash of the key to share its bytes. The first cached read of the object then computed its shape from its keys, hashing each key again. A member whose key is a constant string other than __proto__ now owns a store cache site and calls scr_js_store_probe, which appends the member through the cached shape transition, takes the key bytes from the shape, and leaves the object shaped. Members the probe does not take (Error field names, members past the 64th, a site's first object of a shape) keep scr_dyn_key_set, as do computed keys and literals in module initializers.
30 lines
756 B
JavaScript
30 lines
756 B
JavaScript
// Dynamic-tier property caches across library sessions: objects built empty
|
|
// and filled through untyped stores or built by object literals, read back
|
|
// through untyped loads, and a class instance at the same kind of sites. Each session must start with
|
|
// empty caches, since the shapes their entries named are freed when the
|
|
// previous session ends.
|
|
class Box {
|
|
constructor(v) {
|
|
this.v = v;
|
|
}
|
|
}
|
|
function fill(o, n) {
|
|
o.a = n;
|
|
o.b = n + 1;
|
|
return o;
|
|
}
|
|
function pair(n) {
|
|
return { a: n, b: n + 1 };
|
|
}
|
|
function sum(o) {
|
|
return o.a + o.b;
|
|
}
|
|
function unbox(b) {
|
|
return b.v;
|
|
}
|
|
export function runAll() {
|
|
let total = 0;
|
|
for (let i = 0; i < 100; i++) total += sum(fill({}, i)) + sum(pair(i));
|
|
return total + unbox(new Box(total));
|
|
}
|