barcodes: spell the package in the syntax the compiler now supports - #313
Merged
Merged
Conversation
The package was written around five compiler limitations that no longer exist. Every workaround is replaced by the direct spelling; the emitted JS is equivalent (dom.rip emits byte-identical code but for one semicolon), the encoder oracle is byte-identical on 1452 checks, the decoder oracle identical on 192, and the bench holds its margins. Void definitions compose with readonly. Thirty-three functions and methods whose value nobody uses are now bang-named (`matSet! =!`, `clean!: =>`, `binarize!:`), and the 27 bare trailing `return` lines that stopped a trailing loop from being collected are gone. The nine bare returns that remain are early exits. Range loops count in every form. Twenty hand-counted `while` loops are ranges again (`for i in [n - 1..0] by -1`, `for at in [first...n - 5] by 2`, `for y in [0...bHeight] by chunk` under a cooperative yield), three push-built arrays are comprehensions, and one-statement block loops fold to postfix lines. Per-pixel loops (block thresholds, bitmap rows, resize, finder search) keep block form for readability; the emitted header is the same either way. copyWords splits its quad and remainder passes into two ranges instead of sharing a counter. decodeText indexes its codeword loop directly, so the GS1 position test moves from the post-increment slot 2 to slot 1. `yield from` is `yield*` at its three delegation sites. The three functions that hoisted a result around a tail try/finally return in place, and decodeQR raises its error inside the try so clean() runs during the unwind. The Code 128 subset planner's `own` local is `own` again next to `other`. Verified: package tests 33/33, test:all 26 lanes / 9895 tests, both parity oracles clean. Bench (same session, µs, rip / Paul): encode v8 19.2 / 17.7, v18 55.9 / 59.0; decode raster 38.8 / 116.4, 720p 652 / 1030, 1080p 1490 / 2230, 1080p miss 22800 / 23640 — the same ratios as before the change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/barcodeswas written around five compiler limitations that PRs #308–#312 removed. This replaces every workaround with the direct spelling. Behavior is unchanged: dom.rip emits byte-identical JS but for one semicolon, the encoder oracle is byte-identical on 1452 checks, the decoder oracle identical on 192, and the bench keeps its margins over the reference implementation.Changes
f! =! ->,m!: ->): 33 functions and methods whose value is never used are bang-named; the 27 bare trailingreturnlines that stopped trailing-loop collection are deleted. The 9 bare returns left are early exits.whileloops are ranges again (including descendingby -1, steppedby 2, and variable-step chunk loops under a cooperativeyield); 3 push-built arrays are comprehensions; one-statement block loops fold to postfix. Per-pixel hot loops keep block form for readability (identical header either way).copyWordssplits quad and remainder passes into two ranges.decodeTextindexes directly, so the GS1 position check moves from post-increment slot 2 to slot 1 (covered by the existing GS1 tests).yield*at the three delegation sites.decode,decodeAsync,decodeQRreturn in place instead of hoisting a result;decodeQRraises inside the try soclean()runs during the unwind.ownrestored as the Code 128 subset planner's local, next toother.Diff: 6 files, +114 / −228.
Verification
packages/barcodestests: 33/33bun run test:all: 26 lanes, 9895 tests (includes the package style lint)