This commit reworks the handling of `zig fmt: off/on`. A motivating
example is shown below:
const c = d;
// zig fmt: off
// comment
const a = b;
// zig fmt: on
Before processing the decl `const a = b;`, `renderRoot` looks for
`zig fmt: off` that appears between this decl and the previous one. If
it finds one, it searches for the next `zig fmt: on` that re-enables
reformatting (or EOF if none was found), and copies the input code
between `zig fmt: off` and `zig fmt: on` to the output stream. After
that, it proceeds to the next decl.
The important thing to notice here is that `renderTopLevelDecl` emits
line comment tokens that follow the decl. Therefore, when copying code,
we must be careful not to copy the line comment tokens that already have
been written to the output stream. The original code failed to take this
fact into consideration. It did skip `// zig fmt: off`, but not the
remaining ones. As a result, when the above example is fed as input, it
duplicated the line `// comment`.
This removes the exposed stateless variant since the standard variant
has similar speed now.
Using `./benchmark --filter wyhash --count 1024`, the speed change has
changed from:
wyhash
iterative: 4093 MiB/s [6f76b0d5db7db34c]
small keys: 3132 MiB/s [28c2f43c70000000]
to
wyhash
iterative: 6515 MiB/s [673e9bb86da93ea4]
small keys: 10487 MiB/s [28c2f43c70000000]
This is user specified and the user doesn't necessarily have to use one
of the provided polynomials declared hence we can't use an enum.
Thanks @daurnimator for catching this.
This gives moderate speed improvements when hashing small keys.
The crc/adler/fnv inlining did not provide enough speed up to warrant
the change.
OLD:
wyhash
small keys: 2277 MiB/s [c14617a1e3800000]
siphash(1,3)
small keys: 937 MiB/s [b2919222ed400000]
siphash(2,4)
small keys: 722 MiB/s [3c3d974cc2800000]
fnv1a
small keys: 1580 MiB/s [70155e1cb7000000]
adler32
small keys: 1898 MiB/s [00013883ef800000]
crc32-slicing-by-8
small keys: 2323 MiB/s [0035bf3dcac00000]
crc32-half-byte-lookup
small keys: 218 MiB/s [0035bf3dcac00000]
NEW:
wyhash
small keys: 2775 MiB/s [c14617a1e3800000]
siphash(1,3)
small keys: 1086 MiB/s [b2919222ed400000]
siphash(2,4)
small keys: 789 MiB/s [3c3d974cc2800000]
fnv1a
small keys: 1604 MiB/s [70155e1cb7000000]
adler32
small keys: 1856 MiB/s [00013883ef800000]
crc32-slicing-by-8
small keys: 2336 MiB/s [0035bf3dcac00000]
crc32-half-byte-lookup
small keys: 218 MiB/s [0035bf3dcac00000]
* getrandom libc prototypes had the wrong return type
* `total_read` local variable was unnecessary since the sub-slice
buffer has a length
* I was able to get rid of all the integer casts
* the err == 0 check can be a switch case
* add missing `return` statement