Commit 4b6f350369

Andrew Kelley <andrew@ziglang.org>
2019-04-29 19:48:15
DirectAllocator: move if > 0 condition above @memcpy
Minor improvement to 3c13aa17 as noted by daurnimator
1 parent 3c13aa1
Changed files (1)
std/heap.zig
@@ -141,8 +141,8 @@ pub const DirectAllocator = struct {
                     return shrink(allocator, old_mem, old_align, new_size, new_align);
                 }
                 const result = try alloc(allocator, new_size, new_align);
-                @memcpy(result.ptr, old_mem.ptr, std.math.min(old_mem.len, result.len));
-                if (old_mem.len > 0) {
+                if (old_mem.len != 0) {
+                    @memcpy(result.ptr, old_mem.ptr, std.math.min(old_mem.len, result.len));
                   _ = os.posix.munmap(@ptrToInt(old_mem.ptr), old_mem.len);
                 }
                 return result;