From a84c0f57b5efde85c195cbc706715bf4a4116018 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Mon, 15 Mar 2021 02:39:41 +0200 Subject: cleanup and optimizations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · No longer rewinding a stream being split, just to skip half through it again, which was not only stupid, but inneficient. · No longer using "index" anywhere when working with lists, lest we get accused of not actually doing lists. Signed-off-by: Gediminas Jakutis --- src/util.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index c14a848..2b32a94 100644 --- a/src/util.c +++ b/src/util.c @@ -22,6 +22,21 @@ int stream_rewind(struct stream * const restrict in) return ret; } +int stream_skip(struct stream * const restrict in) +{ + int ret = 0; + size_t ss; + struct entry_l discard; + + ss = in->settings->ss; + + while (ss--) { + in->get(in, &discard); + } + + return ret; +} + int split(struct stream * const src, struct stream * const A, struct stream * const B) { int ret = 0; @@ -57,6 +72,7 @@ int split(struct stream * const src, struct stream * const A, struct stream * co try_s((ret = src->copy(src, A)), err); try_s((ret = cache_create(B)), err); try_s((ret = src->copy(src, B)), err); + stream_rewind(src); } else { A->name = B->name = src->name; A->type = B->type = stream_lite; @@ -64,6 +80,7 @@ int split(struct stream * const src, struct stream * const A, struct stream * co try_s((ret = src->copy(src, A)), err); try_s((ret = stream_open(B)), err); try_s((ret = src->copy(src, B)), err); + stream_rewind(src); } A->settings = B->settings = src->settings; -- cgit v1.2.3