summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2025-08-11 23:36:48 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2025-08-11 23:36:48 +0200
commit7d9ac83b3026a8f308c6be15ac512a22fba20442 (patch)
treed91da56a4ed2897785c6d93d3b22480823f47faa /src
parentbf3a748fcdccdcc8d4a7d170c22db1b13c8bd7b9 (diff)
piece-table: optimization: grow piece when possible
Diffstat (limited to 'src')
-rw-r--r--src/piece-table.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/piece-table.c b/src/piece-table.c
index c6e2375..ba88103 100644
--- a/src/piece-table.c
+++ b/src/piece-table.c
@@ -280,6 +280,19 @@ piece_table_insert (piece_table *pt, size_t pos, char *in, size_t len)
pt->cached_offset -= pt->cached->length;
}
+ /* Optimization!
+ * Add in the end of the buffer, and the end of the piece: enlarge
+ */
+ if ( pt->add.len != 0 &&
+ start->buffer == &pt->add &&
+ pt->cached_offset + start->length == pos &&
+ pt->add.len == start->start + start->length ) {
+ pt->length += len;
+ start->length += len;
+ return;
+ }
+
+
/* Make a new piece and insert it */
new = piece_buffer_bump(pt->pieces);
new->buffer = &pt->add;