Releases: hebcal/gematriya
Release list
v1.1.0
Rewrite conversion for speed and idiomatic Go
Gematriya(5749) drops from 111ns/4 allocs to 35ns/1 alloc; the thousands path from 158ns/6 allocs to 45ns/1 alloc.
The old code carried three inefficiencies from its JS/C/Lisp lineage: string building via +=, which reallocated on every letter; num2digits, which allocated a slice per call and found each digit by counting down from 400 one step at a time; and num2heb, a 20-case switch where an array indexed by the digit does. Half of that switch (500..1000) was unreachable, since num2digits never emits a value above 400.
Digits are now derived with / and %, and letters accumulate in a stack-allocated [16]rune buffer, leaving the returned string as the only allocation. The gershayim is placed by overwriting the final letter and re-appending it, avoiding a separate digit count.
Behavior is unchanged: the new implementation was diffed against the old across 5,010,005 inputs (-10,000..5,000,000 plus large values) with zero mismatches, including the negative-input path that returns "".
Tests become table-driven and cover previously untested edges: 0, negatives, 5000 (elided 5 yields ""), 400, 999, and 115/116, where the 15/16 rule fires beneath a hundreds letter.
go.mod moves 1.13 -> 1.18, the realistic modern floor; the library uses no version-gated features, so a higher directive would only raise the bar for consumers. CI was pinned to the long-EOL Go 1.13 and now runs a 1.18/stable matrix with go vet.
Full Changelog: v1.0.1...v1.1.0