aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-08 12:24:13 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-08 12:24:13 +0200
commitc6b0e43f3fd8fbafc323ffe14a2f12312d0bc64a (patch)
tree5d49ee11354c513f34d21521737bd759b1aed0b3
parent7561ba6539cf5bb1afd87315911b39a1ff3fceb8 (diff)
downloadvis-c6b0e43f3fd8fbafc323ffe14a2f12312d0bc64a.tar.gz
vis-c6b0e43f3fd8fbafc323ffe14a2f12312d0bc64a.tar.xz
Use named struct initializers where appropriate
-rw-r--r--text.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/text.c b/text.c
index 2b812be..4a4cd80 100644
--- a/text.c
+++ b/text.c
@@ -414,35 +414,27 @@ static void piece_init(Piece *p, Piece *prev, Piece *next, const char *data, siz
* in particular if pos is zero, the begin sentinel piece is returned.
*/
static Location piece_get_intern(Text *ed, size_t pos) {
- Location loc = {};
size_t cur = 0;
for (Piece *p = &ed->begin; p->next; p = p->next) {
- if (cur <= pos && pos <= cur + p->len) {
- loc.piece = p;
- loc.off = pos - cur;
- break;
- }
+ if (cur <= pos && pos <= cur + p->len)
+ return (Location){ .piece = p, .off = pos - cur };
cur += p->len;
}
- return loc;
+ return (Location){ 0 };
}
/* similiar to piece_get_intern but usable as a public API. returns the piece
* holding the text at byte offset pos. never returns a sentinel piece. */
static Location piece_get_extern(Text *ed, size_t pos) {
- Location loc = {};
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;
- break;
- }
+ if (cur <= pos && pos < cur + p->len)
+ return (Location){ .piece = p, .off = pos - cur };
cur += p->len;
}
- return loc;
+ return (Location){ 0 };
}
/* allocate a new change, associate it with current action or a newly