refactor: adapt diffz module to Buffer text caching API
This commit is contained in:
parent
ed69048e91
commit
b25e099a84
1 changed files with 12 additions and 15 deletions
|
|
@ -25,24 +25,21 @@ pub const AsyncDiffer = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_from_root(root: Buffer.Root, eol_mode: Buffer.EolMode) ![]const u8 {
|
|
||||||
var text: std.Io.Writer.Allocating = .init(std.heap.c_allocator);
|
|
||||||
defer text.deinit();
|
|
||||||
try root.store(&text.writer, eol_mode);
|
|
||||||
return text.toOwnedSlice();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const CallBack = fn (from: tp.pid_ref, data: usize, edits: []Diff) void;
|
pub const CallBack = fn (from: tp.pid_ref, data: usize, edits: []Diff) void;
|
||||||
|
|
||||||
pub fn diff_buffer(self: @This(), cb: *const CallBack, cb_data: usize, buffer: *const Buffer) tp.result {
|
pub fn diff_buffer(self: @This(), cb: *const CallBack, cb_data: usize, buffer: *Buffer) tp.result {
|
||||||
|
const allocator = std.heap.c_allocator;
|
||||||
const eol_mode = buffer.file_eol_mode;
|
const eol_mode = buffer.file_eol_mode;
|
||||||
const text_dst = text_from_root(buffer.root, eol_mode) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
const text_dst = allocator.dupe(u8, buffer.store_to_string_cached(buffer.root, eol_mode)) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
errdefer std.heap.c_allocator.free(text_dst);
|
errdefer allocator.free(text_dst);
|
||||||
const text_src = if (buffer.get_vcs_content()) |vcs_content|
|
const text_src = allocator.dupe(
|
||||||
std.heap.c_allocator.dupe(u8, vcs_content) catch |e| return tp.exit_error(e, @errorReturnTrace())
|
u8,
|
||||||
|
if (buffer.get_vcs_content()) |vcs_content|
|
||||||
|
vcs_content
|
||||||
else
|
else
|
||||||
text_from_root(buffer.last_save orelse return, eol_mode) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
buffer.store_last_save_to_string_cached(eol_mode) orelse return,
|
||||||
errdefer std.heap.c_allocator.free(text_src);
|
) catch |e| return tp.exit_error(e, @errorReturnTrace());
|
||||||
|
errdefer allocator.free(text_src);
|
||||||
const text_dst_ptr: usize = if (text_dst.len > 0) @intFromPtr(text_dst.ptr) else 0;
|
const text_dst_ptr: usize = if (text_dst.len > 0) @intFromPtr(text_dst.ptr) else 0;
|
||||||
const text_src_ptr: usize = if (text_src.len > 0) @intFromPtr(text_src.ptr) else 0;
|
const text_src_ptr: usize = if (text_src.len > 0) @intFromPtr(text_src.ptr) else 0;
|
||||||
if (self.pid) |pid| try pid.send(.{ "D", @intFromPtr(cb), cb_data, text_dst_ptr, text_dst.len, text_src_ptr, text_src.len });
|
if (self.pid) |pid| try pid.send(.{ "D", @intFromPtr(cb), cb_data, text_dst_ptr, text_dst.len, text_src_ptr, text_src.len });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue