CE optimize KB_DELETE
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m6s

This commit is contained in:
2026-03-08 12:22:59 +01:00
parent 0de0b4c1ae
commit a8d21b2d67
3 changed files with 24 additions and 10 deletions

View File

@@ -283,10 +283,7 @@ void edit_start (const char* file_path, const char* text) {
struct edit_line* next_line = list_entry (next, struct edit_line, lines_link);
size_t next_len = gapbuffer_length (&next_line->gb);
for (size_t i = 0; i < next_len; i++) {
char chr = gapbuffer_at (&next_line->gb, i);
gapbuffer_insert (&wrealloc, NULL, &editor.current_line->gb, chr);
}
gapbuffer_concat (&wrealloc, NULL, &editor.current_line->gb, &next_line->gb);
list_remove (editor.lines, &next_line->lines_link);
free (next_line->gb.buffer);

View File

@@ -113,9 +113,25 @@ char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffe
return res;
}
char gapbuffer_at (struct gapbuffer* gb, size_t index) {
if (index < gb->gap_start)
return gb->buffer[index];
else
return gb->buffer[index + (gb->gap_end - gb->gap_start)];
void gapbuffer_concat (gb_realloc_func_t reallocfn, void* ctx, struct gapbuffer* dest,
struct gapbuffer* src) {
size_t src_len = gapbuffer_length (src);
if (src_len == 0)
return;
while ((dest->gap_end - dest->gap_start) < src_len)
gapbuffer_grow (reallocfn, ctx, dest);
gapbuffer_move (dest, gapbuffer_length (dest));
size_t part1_len = src->gap_start;
memcpy (dest->buffer + dest->gap_start, src->buffer, part1_len);
dest->gap_start += part1_len;
size_t part2_len = src->size - src->gap_end;
if (part2_len > 0) {
memcpy (dest->buffer + dest->gap_start, src->buffer + src->gap_end, part2_len);
dest->gap_start += part2_len;
}
}

View File

@@ -33,6 +33,7 @@ size_t gapbuffer_length (struct gapbuffer* gb);
char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffer* gb, size_t pos);
char gapbuffer_at (struct gapbuffer* gb, size_t index);
void gapbuffer_concat (gb_realloc_func_t reallocfn, void* ctx, struct gapbuffer* dest,
struct gapbuffer* src);
#endif // _GAPBUFFER_H