aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-07-22 15:37:24 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-07-22 15:37:24 +0200
commit15e497645f71c66ae27bd0ed81f0d7815a0da382 (patch)
tree256b504d026da21596c345fd5c7fcc941326ca5b
parent111126d4f3a36ea005fbb19881c49c008b30acfd (diff)
downloadvis-15e497645f71c66ae27bd0ed81f0d7815a0da382.tar.gz
vis-15e497645f71c66ae27bd0ed81f0d7815a0da382.tar.xz
Remove redundant function
-rw-r--r--editor.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/editor.c b/editor.c
index ed2a870..0962089 100644
--- 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,