diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-03-14 13:55:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-03-14 13:55:14 -0700 |
commit | c9327e28c240c08b11145e55d909e5ccf6b5f870 (patch) | |
tree | f64348e78a72210d95f81c1dccb7397bae23c290 /lib.c | |
parent | 488bc2f599aa6a2be792e36033ce087a9c5c7577 (diff) | |
download | txr-c9327e28c240c08b11145e55d909e5ccf6b5f870.tar.gz txr-c9327e28c240c08b11145e55d909e5ccf6b5f870.tar.bz2 txr-c9327e28c240c08b11145e55d909e5ccf6b5f870.zip |
cat-str: seq_iter conversion,
* lib.c (cat_str): Traverse sequences of strings efficiently
using seq_iter framework.
* txr.1: Document.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -4830,22 +4830,35 @@ static val cat_str_get(struct cat_str *cs) return string_own(cs->str); } -val cat_str(val list, val sep) +val cat_str(val items, val sep) { val self = lit("cat-str"); - val iter; + seq_iter_t item_iter; + val item, peek = nil; + int more = 0; struct cat_str cs; wchar_t onech[] = wini(" "); + cat_str_init(&cs, sep, wref(onech), self); - for (iter = list; iter != nil; iter = cdr(iter)) - cat_str_measure(&cs, car(iter), cdr(iter) != nil, self); + seq_iter_init(self, &item_iter, items); + more = seq_get(&item_iter, &item); + while (more) + { + cat_str_measure(&cs, item, more = seq_get(&item_iter, &peek), self); + item = peek; + } cat_str_alloc(&cs); - for (iter = list; iter != nil; iter = cdr(iter)) - cat_str_append(&cs, car(iter), cdr(iter) != nil, self); + seq_iter_init(self, &item_iter, items); + more = seq_get(&item_iter, &item); + while (more) + { + cat_str_append(&cs, item, more = seq_get(&item_iter, &peek), self); + item = peek; + } return cat_str_get(&cs); } |