From 70a8f737d4335f7c76c248febc9ad66abc394044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 10 Oct 2020 10:41:51 +0200 Subject: text: provide public text_iterator_init It can be used to initialize a (stack allocated) Iterator structure, avoiding the copying of the return value as done by text_iterator_get which depending on the implementation might be problematic. --- text.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'text.c') diff --git a/text.c b/text.c index 38bec1a..6d93334 100644 --- a/text.c +++ b/text.c @@ -1403,10 +1403,14 @@ static bool iterator_init(Iterator *it, size_t pos, Piece *p, size_t off) { return text_iterator_valid(it); } +bool text_iterator_init(const Text *txt, Iterator *it, size_t pos) { + Location loc = piece_get_extern(txt, pos); + return iterator_init(it, pos, loc.piece, loc.off); +} + Iterator text_iterator_get(const Text *txt, size_t pos) { Iterator it; - Location loc = piece_get_extern(txt, pos); - iterator_init(&it, pos, loc.piece, loc.off); + text_iterator_init(txt, &it, pos); return it; } -- cgit v1.2.3