summaryrefslogtreecommitdiff
path: root/src/piece-table.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/piece-table.c')
-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;