use libc memcpy/memmove instead of std.mem if available

This commit is contained in:
Mitchell Hashimoto
2022-11-08 19:01:45 -08:00
parent a471eaf980
commit d1718e6cbf
7 changed files with 47 additions and 11 deletions

View File

@@ -60,6 +60,7 @@ const color = @import("color.zig");
const point = @import("point.zig");
const CircBuf = @import("circ_buf.zig").CircBuf;
const Selection = @import("Selection.zig");
const fastmem = @import("../fastmem.zig");
const log = std.log.scoped(.screen);
@@ -400,7 +401,7 @@ pub const Row = struct {
// If the source has no graphemes (likely) then this is fast.
const end = @min(src.storage.len, self.storage.len);
if (!src.storage[0].header.flags.grapheme) {
std.mem.copy(StorageCell, self.storage[1..], src.storage[1..end]);
fastmem.copy(StorageCell, self.storage[1..], src.storage[1..end]);
return;
}
@@ -642,7 +643,7 @@ pub const GraphemeData = union(enum) {
.three => |v| self.* = .{ .four = .{ v[0], v[1], v[2], cp } },
.four => |v| {
const many = try alloc.alloc(u21, 5);
std.mem.copy(u21, many, &v);
fastmem.copy(u21, many, &v);
many[4] = cp;
self.* = .{ .many = many };
},
@@ -898,7 +899,7 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi
const src_offset = count * (self.cols + 1);
const src = buf[src_offset..];
assert(@ptrToInt(dst.ptr) < @ptrToInt(src.ptr));
std.mem.copy(StorageCell, dst, src);
fastmem.move(StorageCell, dst, src);
}
{
@@ -1449,7 +1450,7 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void {
// The row doesn't fit, meaning we have to soft-wrap the
// new row but probably at a diff boundary.
std.mem.copy(
fastmem.copy(
StorageCell,
new_row.storage[x + 1 ..],
wrapped_cells[wrapped_i .. wrapped_i + copy_len],

View File

@@ -13,6 +13,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const testing = std.testing;
const assert = std.debug.assert;
const fastmem = @import("../fastmem.zig");
/// Unit is the type we use per tabstop unit (see file docs).
const Unit = u8;
@@ -129,7 +130,7 @@ pub fn resize(self: *Tabstops, alloc: Allocator, cols: usize) !void {
// Note: we can probably try to realloc here but I'm not sure it matters.
const new = try alloc.alloc(Unit, size);
if (self.dynamic_stops.len > 0) {
std.mem.copy(Unit, new, self.dynamic_stops);
fastmem.copy(Unit, new, self.dynamic_stops);
alloc.free(self.dynamic_stops);
}

View File

@@ -1,6 +1,8 @@
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const trace = @import("tracy").trace;
const fastmem = @import("../fastmem.zig");
/// Returns a circular buffer containing type T.
pub fn CircBuf(comptime T: type, comptime default: T) type {
@@ -82,13 +84,13 @@ pub fn CircBuf(comptime T: type, comptime default: T) type {
}
if (!self.full and self.head >= self.tail) {
std.mem.copy(T, buf, self.storage[self.tail..self.head]);
fastmem.copy(T, buf, self.storage[self.tail..self.head]);
return;
}
const middle = self.storage.len - self.tail;
std.mem.copy(T, buf, self.storage[self.tail..]);
std.mem.copy(T, buf[middle..], self.storage[0..self.head]);
fastmem.copy(T, buf, self.storage[self.tail..]);
fastmem.copy(T, buf[middle..], self.storage[0..self.head]);
}
/// Returns if the buffer is currently empty. To check if its
@@ -130,6 +132,9 @@ pub fn CircBuf(comptime T: type, comptime default: T) type {
/// the end of our buffer. This never "rotates" the buffer because
/// the offset can only be within the size of the buffer.
pub fn getPtrSlice(self: *Self, offset: usize, slice_len: usize) [2][]T {
const tracy = trace(@src());
defer tracy.end();
// Note: this assertion is very important, it hints the compiler
// which generates ~10% faster code than without it.
assert(offset + slice_len <= self.capacity());