fastmem: rotateOnce

This commit is contained in:
Qwerasd
2024-03-25 19:12:55 -06:00
parent ddd7f3e706
commit d74ea89056
2 changed files with 11 additions and 2 deletions

View File

@ -22,5 +22,13 @@ pub inline fn copy(comptime T: type, dest: []T, source: []const T) void {
}
}
/// Same as std.mem.rotate(T, items, 1) but more efficient by using memmove
/// and a tmp var for the single rotated item instead of 3 calls to reverse.
pub inline fn rotateOnce(comptime T: type, items: []T) void {
const tmp = items[0];
move(T, items[0..items.len - 1], items[1..items.len]);
items[items.len - 1] = tmp;
}
extern "c" fn memcpy(*anyopaque, *const anyopaque, usize) *anyopaque;
extern "c" fn memmove(*anyopaque, *const anyopaque, usize) *anyopaque;

View File

@ -6,6 +6,7 @@ const PageList = @This();
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const fastmem = @import("../fastmem.zig");
const point = @import("point.zig");
const pagepkg = @import("page.zig");
const stylepkg = @import("style.zig");
@ -2001,7 +2002,7 @@ pub fn eraseRow(
// In order to move the following rows up we rotate the rows array by 1.
// The rotate operation turns e.g. [ 0 1 2 3 ] in to [ 1 2 3 0 ], which
// works perfectly to move all of our elements where they belong.
std.mem.rotate(Row, rows[pn.y..page.data.size.rows], 1);
fastmem.rotateOnce(Row, rows[pn.y..page.data.size.rows]);
// We adjust the tracked pins in this page, moving up any that were below
// the removed row.
@ -2038,7 +2039,7 @@ pub fn eraseRow(
page = next;
rows = next_rows;
std.mem.rotate(Row, rows[0..page.data.size.rows], 1);
fastmem.rotateOnce(Row, rows[0..page.data.size.rows]);
// Our tracked pins for this page need to be updated.
// If the pin is in row 0 that means the corresponding row has