aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-07-22 14:54:15 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-07-22 14:54:15 +0200
commit111126d4f3a36ea005fbb19881c49c008b30acfd (patch)
tree42c47ef203ac6f15d506c7cd3e178b1f75750991
parent1000482506cc5a419a7f6be026cc1c8e8d89ce67 (diff)
downloadvis-111126d4f3a36ea005fbb19881c49c008b30acfd.tar.gz
vis-111126d4f3a36ea005fbb19881c49c008b30acfd.tar.xz
Remove unnecessary special case for inserting into an empty document
-rw-r--r--editor.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/editor.c b/editor.c
index a96cc28..ed2a870 100644
--- a/editor.c
+++ b/editor.c
@@ -416,17 +416,6 @@ static void change_free(Change *c) {
free(c);
}
-static Piece* editor_insert_empty(Editor *ed, char *content, size_t len) {
- Piece *p = piece_alloc(ed);
- if (!p)
- return NULL;
- piece_init(&ed->begin, NULL, p, NULL, 0);
- piece_init(p, &ed->begin, &ed->end, content, len);
- piece_init(&ed->end, p, NULL, NULL, 0);
- ed->size = len;
- return p;
-}
-
/* When inserting new data there are 2 cases to consider.
*
* - in the first the insertion point falls into the middle of an exisiting
@@ -470,15 +459,6 @@ bool editor_insert(Editor *ed, size_t pos, char *text) {
if (!(text = buffer_store(ed, text, len)))
return false;
- /* special case for an empty document */
- if (ed->size == 0) {
- Piece *p = editor_insert_empty(ed, text, len);
- if (!p)
- return false;
- span_init(&c->new, p, p);
- span_init(&c->old, NULL, NULL);
- return true;
- }
Piece *new = NULL;
@@ -610,8 +590,14 @@ Editor *editor_load(const char *filename) {
ed->buf.content = mmap(NULL, ed->info.st_size, PROT_READ, MAP_SHARED, ed->fd, 0);
if (ed->buf.content == MAP_FAILED)
goto out;
- if (!editor_insert_empty(ed, ed->buf.content, ed->buf.size))
+
+ Piece *p = piece_alloc(ed);
+ if (!p)
goto out;
+ piece_init(&ed->begin, NULL, p, NULL, 0);
+ piece_init(p, &ed->begin, &ed->end, ed->buf.content, ed->buf.size);
+ piece_init(&ed->end, p, NULL, NULL, 0);
+ ed->size = ed->buf.size;
}
return ed;
out: