summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-03-15 02:39:41 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-03-15 02:39:41 +0200
commita84c0f57b5efde85c195cbc706715bf4a4116018 (patch)
treed9c5715d637dd870ca5ffe6f3bb031297c8d2f45 /src/util.c
parent111d08d814720966d12fd57b58331c149df7e6cf (diff)
downloadalgos-ld1-e4b5cddfe09cd5d25dea950467380c20ba7f7986.tar.gz
algos-ld1-e4b5cddfe09cd5d25dea950467380c20ba7f7986.tar.bz2
algos-ld1-e4b5cddfe09cd5d25dea950467380c20ba7f7986.zip
cleanup and optimizations.algos-ld1-1.0
· 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 <gediminas@varciai.lt>
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c17
1 files changed, 17 insertions, 0 deletions
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;