CE improve editor performace by reducing amount of copying
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m31s

This commit is contained in:
2026-03-06 21:59:41 +01:00
parent eb3238bf85
commit 49059f4bfa
4 changed files with 45 additions and 53 deletions

View File

@@ -72,22 +72,6 @@ void gapbuffer_backspace (struct gapbuffer* gb) {
gb->gap_start--;
}
char* gapbuffer_get_string (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffer* gb) {
size_t size = gb->size - (gb->gap_end - gb->gap_start);
char* str = mallocfn (ctx, size + 1);
if (str == NULL)
return NULL;
memcpy (str, gb->buffer, gb->gap_start);
memcpy (str + gb->gap_start, gb->buffer + gb->gap_end, gb->size - gb->gap_end);
str[size] = '\0';
return str;
}
size_t gapbuffer_length (struct gapbuffer* gb) { return gb->size - (gb->gap_end - gb->gap_start); }
char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffer* gb, size_t pos) {
@@ -128,17 +112,3 @@ char* gapbuffer_string_at (gb_malloc_func_t mallocfn, void* ctx, struct gapbuffe
res[written] = '\0';
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_delete_at (struct gapbuffer* gb, size_t index) {
gapbuffer_move (gb, index);
if (gb->gap_end < gb->size)
gb->gap_end++;
}