commit b8cb780230197ce7e7e3059c7e37e1a40d9dcfc2 (tree)
parent b3c6a3b047cb248afb0d61ae723ae41aeab9289b
Author: Erik Schlyter <erik@erisc.se>
Date: Sat, 14 Feb 2026 23:06:28 +0100
std.Io.Writer: Make Hashing support pointers.
The line `const hasher = &this.hasher` was making the local variable
`hasher` a double-pointer when `Hasher` already is a pointer to a
hasher, which the line `hasher.update` would not dereference. By
removing the local `hasher` value we allow `Hashing` to accept pointer
types as well.
The contrasting `Hashed` function already follows this pattern.
Diffstat:
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig
@@ -2524,15 +2524,14 @@ pub fn Hashing(comptime Hasher: type) type {
fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
const this: *@This() = @alignCast(@fieldParentPtr("writer", w));
- const hasher = &this.hasher;
- hasher.update(w.buffered());
+ this.hasher.update(w.buffered());
w.end = 0;
var n: usize = 0;
for (data[0 .. data.len - 1]) |slice| {
- hasher.update(slice);
+ this.hasher.update(slice);
n += slice.len;
}
- for (0..splat) |_| hasher.update(data[data.len - 1]);
+ for (0..splat) |_| this.hasher.update(data[data.len - 1]);
return n + splat * data[data.len - 1].len;
}
};