The original implementation of this was a bit difficult to read and understand. This is just a refactor to make the intention of the method a little easier to comprehend. Added some docs.
Also ran some benchmarks and this way is slightly faster:
old 11.59k ( 86.27µs) (± 1.24%) 578kB/op 1.45× slower
new 16.75k ( 59.70µs) (± 0.75%) 406kB/op fastest
Checklist
[x] - An issue already exists detailing the issue/or feature request that this PR fixes
[x] - All specs are formatted with crystal tool format spec src
[x] - Inline documentation has been added and/or updated
[x] - Lucky builds on docker with ./script/setup
[x] - All builds and specs pass on docker with ./script/test
Purpose
Fixes #1825
Description
The original implementation of this was a bit difficult to read and understand. This is just a refactor to make the intention of the method a little easier to comprehend. Added some docs.
Also ran some benchmarks and this way is slightly faster:
Checklist
crystal tool format spec src
./script/setup
./script/test