authorgravatar for erik@erisc.seErik Schlyter <erik@erisc.se> 2026-02-14 23:06:28+01:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-05-30 02:27:54+02:00
logb8cb780230197ce7e7e3059c7e37e1a40d9dcfc2
tree95ac25d570b15798bf5a46efbe9f63ebdf1ee369
parentb3c6a3b047cb248afb0d61ae723ae41aeab9289b

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.

1 files changed, 3 insertions(+), 4 deletions(-)

lib/std/Io/Writer.zig+3-4
...@@ -2524,15 +2524,14 @@ pub fn Hashing(comptime Hasher: type) type {...@@ -2524,15 +2524,14 @@ pub fn Hashing(comptime Hasher: type) type {
25242524
2525 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {2525 fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
2526 const this: *@This() = @alignCast(@fieldParentPtr("writer", w));2526 const this: *@This() = @alignCast(@fieldParentPtr("writer", w));
2527 const hasher = &this.hasher;2527 this.hasher.update(w.buffered());
2528 hasher.update(w.buffered());
2529 w.end = 0;2528 w.end = 0;
2530 var n: usize = 0;2529 var n: usize = 0;
2531 for (data[0 .. data.len - 1]) |slice| {2530 for (data[0 .. data.len - 1]) |slice| {
2532 hasher.update(slice);2531 this.hasher.update(slice);
2533 n += slice.len;2532 n += slice.len;
2534 }2533 }
2535 for (0..splat) |_| hasher.update(data[data.len - 1]);2534 for (0..splat) |_| this.hasher.update(data[data.len - 1]);
2536 return n + splat * data[data.len - 1].len;2535 return n + splat * data[data.len - 1].len;
2537 }2536 }
2538 };2537 };