While I've been looking at the code I wondered if the C compiler
will fur sure pull that one test out of the for-loop.
Maybe it's better no have it there at the first place.
IMHO the code is not more confusing to read this way and should
run better in case the C compiler is not smart enough.
The two spots are in runtime.c C_a_i_list and C_h_list.
In this case a diff seems worse to me than a citation;
The current code is:
C_word C_a_i_list(C_word **a, int c, ...)
{
va_list v;
C_word x, last, current,
first = C_SCHEME_END_OF_LIST;
va_start(v, c);
for(last = C_SCHEME_UNDEFINED; c--; last = current) {
x = va_arg(v, C_word);
current = C_a_pair(a, x, C_SCHEME_END_OF_LIST);
if(last != C_SCHEME_UNDEFINED)
C_set_block_item(last, 1, current);
else first = current;
}
va_end(v);
return first;
}
Here my current (tested) replacement:
C_word C_a_i_list(C_word **a, int c, ...)
{
va_list v;
C_word x, last, current, first;
va_start(v, c);
if(c--) {
x = va_arg(v, C_word);
first = last = C_a_pair(a, x, C_SCHEME_END_OF_LIST);
for(; c--; last = current) {
x = va_arg(v, C_word);
current = C_a_pair(a, x, C_SCHEME_END_OF_LIST);
C_set_block_item(last, 1, current);
}
} else {
first = C_SCHEME_END_OF_LIST;
}
va_end(v);
return first;
}
C_word C_h_list(int c, ...)
{
/* Similar to C_a_i_list(), but put slots with nursery data into mutation
stack: */
va_list v;
C_word x, last, current, first;
va_start(v, c);
if(c--) {
x = va_arg(v, C_word);
first = last = C_a_pair(C_heaptop, x, C_SCHEME_END_OF_LIST);
for(; c--; last = current) {
x = va_arg(v, C_word);
current = C_a_pair(C_heaptop, x, C_SCHEME_END_OF_LIST);
if(C_in_stackp(x))
C_mutate(&C_u_i_car(current), x);
C_set_block_item(last, 1, current);
}
} else {
first = C_SCHEME_END_OF_LIST;
}
va_end(v);
return first;
}
Note that I'm tempted to move the va_start/va_end into the "if".
I'm just unsure whether or not that's allowed by C standards.
(But I can't see how it could harm.)
/Jörg
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users