vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 36da2d195fb2c9ef38eb95cbce6ced7220607823
parent 20b6c124912799f914c3fa3b11fbd377462f17b6
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 22 Jul 2014 15:37:24 +0200

Remove redundant function

Diffstat:
Meditor.c | 23+++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/editor.c b/editor.c @@ -358,7 +358,8 @@ static void piece_init(Piece *p, Piece *prev, Piece *next, char *content, size_t p->len = len; } -/* returns the piece holding the text at byte offset pos */ +/* returns the piece holding the text at byte offset pos. + * if pos is zero, then the begin sentinel piece is returned. */ static Location piece_get(Editor *ed, size_t pos) { Location loc = {}; // TODO: handle position at end of file: pos+1 @@ -375,22 +376,6 @@ static Location piece_get(Editor *ed, size_t pos) { return loc; } -static Location piece_get_public(Editor *ed, size_t pos) { - Location loc = {}; - // TODO: handle position at end of file: pos+1 - size_t cur = 0; - for (Piece *p = ed->begin.next; p->next; p = p->next) { - if (cur <= pos && pos <= cur + p->len) { - loc.piece = p; - loc.off = pos - cur; - return loc; - } - cur += p->len; - } - - return loc; -} - /* allocate a new change, associate it with current action or a newly * allocated one if none exists. */ static Change *change_alloc(Editor *ed) { @@ -770,8 +755,10 @@ bool editor_modified(Editor *ed) { } Iterator editor_iterator_get(Editor *ed, size_t pos) { - Location loc = piece_get_public(ed, pos); + Location loc = piece_get(ed, pos); Piece *p = loc.piece; + if (p == &ed->begin) + p = p->next; return (Iterator){ .piece = p, .text = p ? p->content + loc.off : NULL,