mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Issue #132 - list->string enhancements
- More efficient string construction, only do one alloca/copy - Allows null characters within a created string without truncating string length.
This commit is contained in:
parent
12770291b7
commit
7e0c7a1435
1 changed files with 10 additions and 12 deletions
22
runtime.c
22
runtime.c
|
@ -1594,21 +1594,19 @@ object Cyc_list2string(void *data, object cont, object lst)
|
|||
object len;
|
||||
|
||||
Cyc_check_pair_or_null(data, lst);
|
||||
|
||||
len = Cyc_length(data, lst); // Inefficient, walks whole list
|
||||
buf = alloca(sizeof(char) * (obj_obj2int(len) + 1));
|
||||
while ((lst != NULL)) {
|
||||
if (!obj_is_char(car(lst))) {
|
||||
Cyc_rt_raise2(data, "Expected character but received", car(lst));
|
||||
}
|
||||
buf[i++] = obj_obj2char(car(lst));
|
||||
lst = cdr(lst);
|
||||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
//{ make_string_noalloc(str, buf, i);
|
||||
{
|
||||
make_string(str, buf);
|
||||
make_string_noalloc(str, NULL, (obj_obj2int(len)));
|
||||
str.str = buf = alloca(sizeof(char) * (obj_obj2int(len) + 1));
|
||||
while ((lst != NULL)) {
|
||||
if (!obj_is_char(car(lst))) {
|
||||
Cyc_rt_raise2(data, "Expected character but received", car(lst));
|
||||
}
|
||||
buf[i++] = obj_obj2char(car(lst));
|
||||
lst = cdr(lst);
|
||||
}
|
||||
buf[i] = '\0';
|
||||
_return_closcall1(data, cont, &str);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue