Skip to content

Commit 9b2b650

Browse files
committed
size: dedupe width/height spelling and extend the name-table pack to dictionary keys
Source (both help every build): - save() no longer re-spells x/y/width/height/mipLevel when forwarding to readTexture — readTexture derives the identical defaults from opts itself; only the forced Ctor override remains ({ ...opts, Ctor: U8 }). - resizeCanvas builds its return value through sz(), so the width/height keys outside sz are spelled one less time ({ ...sz(width, height), changed }). Build (pack-gated, so gzip-delivered builds are untouched): - The name-table pack gains a second candidate class, KEY_CANDIDATES: dictionary keys (width, height, format, usage, …) that the member-only pass must refuse. They are aliased in both positions — .name → [$x] and name: → [$x]: — because a computed key evaluates to the identical string, so the descriptor the browser sees never changes. A string mask (new maskStrings, sharing mapTemplateText's walk) proves no rewrite can land inside a string or template literal, and any occurrence that is neither shape disqualifies the name for that build. - Pack selection is now price-then-apply: every candidate is priced against its own table-slot cost, and the set as a whole must clear the fixed let[]="".split(",") skeleton — previously uncharged, which let a lone marginal name pack at a net code loss. The legend comment's size is now logged where it is appended (it is documentation on its own line, not code). Code line: bare tiny -20B, full-featured tiny -102B, min -46B. Files with packComment on grow ~1-2B from the longer legend; packComment: false keeps the whole saving. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FrkUU5GGyzvhujesWXZt1k
1 parent 3146270 commit 9b2b650

4 files changed

Lines changed: 136 additions & 18 deletions

File tree

dist/tinywebgpu.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tinywebgpu.tiny.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tinywebgpu.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ ${main}
706706
width = fit(canvas.clientWidth, canvas.width), height = fit(canvas.clientHeight, canvas.height),
707707
changed = canvas.width !== width || canvas.height !== height,
708708
changed && (canvas.width = width, canvas.height = height),
709-
{ width, height, changed }),
709+
// sz spells the width/height keys once for the whole library — reuse it here too.
710+
{ ...sz(width, height), changed }),
710711
} : {}),
711712

712713
...(F_SHOW ? {
@@ -760,7 +761,10 @@ ${main}
760761
if (!/^(rgba|bgra)8unorm(-srgb)?$/.test(tex.format))
761762
err(19, MSG && `save: needs an 8-bit RGBA texture, got '${tex.format}'. Render it into an rgba8unorm target first.`);
762763
let [width, height] = texWH(tex, opts);
763-
let px = await S.readTexture(tex, { x: opts.x, y: opts.y, width, height, mipLevel: opts.mipLevel, Ctor: U8 });
764+
// readTexture derives the same x/y/width/height/mipLevel defaults from `opts` itself;
765+
// save's extra keys (type, quality, download) are ignored there, and Ctor spread last
766+
// always wins, so the pixels come back as bytes whatever the caller passed.
767+
let px = await S.readTexture(tex, { ...opts, Ctor: U8 });
764768
// ImageData is RGBA; the canvas format is BGRA on most platforms, so swap the ends.
765769
if (tex.format.startsWith('bgra'))
766770
for (let i = 0; i < px.length; i += 4) { let b = px[i]; px[i] = px[i + 2]; px[i + 2] = b; }

0 commit comments

Comments
 (0)