mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-27 21:48:38 +00:00
fastmem non-libc needs to use copyBackwards if dest > src
This fixes test failures when Ghostty's core is run without libc. Ghostty in the real world (all built executables) require libc so this bug has never been hit before, but I'm working on a libc-less core and this caused real test failures (so its already tested, as well).
This commit is contained in:
@@ -2,13 +2,20 @@ const std = @import("std");
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
/// Same as std.mem.copyForwards but prefers libc memmove if it is available
|
/// Same as std.mem.copyForwards/Backwards but prefers libc memmove if it is
|
||||||
/// because it is generally much faster.
|
/// available because it is generally much faster.
|
||||||
pub inline fn move(comptime T: type, dest: []T, source: []const T) void {
|
pub inline fn move(comptime T: type, dest: []T, source: []const T) void {
|
||||||
if (builtin.link_libc) {
|
if (builtin.link_libc) {
|
||||||
_ = memmove(dest.ptr, source.ptr, source.len * @sizeOf(T));
|
_ = memmove(dest.ptr, source.ptr, source.len * @sizeOf(T));
|
||||||
} else {
|
} else {
|
||||||
std.mem.copyForwards(T, dest, source);
|
// Depending on the ordering of the copy, we need to use the
|
||||||
|
// proper call here. Unfortunately this function call is
|
||||||
|
// too generic to know this at comptime.
|
||||||
|
if (@intFromPtr(dest.ptr) <= @intFromPtr(source.ptr)) {
|
||||||
|
std.mem.copyForwards(T, dest, source);
|
||||||
|
} else {
|
||||||
|
std.mem.copyBackwards(T, dest, source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user