This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Kill the SCM_NIMPs
- To: Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Kill the SCM_NIMPs
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Thu, 6 Jan 2000 18:32:47 +0100 (MET)
Hi.
After Greg's famous patch, it has been possible to get rid of a thousand
calls to SCM_NIMP. My believe is, that SCM_NIMP and also SCM_IMP are
extremely low level structures that should be very rarely used. However,
I realized that there are still quite a lot of them. Looking closer, I
figured out that many of these are just used as a replacement for
SCM_NNULLP (or SCM_NULLP), for example when cdr'ing along a variable that
is known to be a list.
The funny thing (after having that infamous cycle-counting debate) is,
that when you look at the implementation of SCM_NIMP and compare that
with SCM_NNULLP you realize, that SCM_NNULLP is only a comparison of a SCM
value with the constant SCM_EOL, while SCM_NIMP requires to extract a
single bit from a SCM value.
It's just a guess, but I assume that using SCM_NIMP instead of SCM_NNULLP
(in places where it is appropriate) is not only obfuscating the
semantics of the code, but also might lead to a performance penalty.
Example: This code is extracted from backtrace.c
-------------------------------------------------------------------------
SCM_DEFINE (scm_set_print_params_x, "set-print-params!", 1, 0, 0,
(SCM params),
"")
#define FUNC_NAME s_scm_set_print_params_x
{
int i, n = scm_ilength (params);
SCM ls;
print_params_t *new_params;
SCM_ASSERT (n >= 1, params, SCM_ARG2, FUNC_NAME);
for (ls = params; SCM_NIMP (ls); ls = SCM_CDR (ls))
SCM_ASSERT (scm_ilength (SCM_CAR (params)) == 2
...
-------------------------------------------------------------------------
First, the assertion makes sure that 'params' is a proper list and has at
least one element. From then on, SCM_NIMP is used to test whether the end
of that list is reached. Obviously, the use of SCM_NNULLP would much
closer reflect the semantics.
I will be glad to help 'kill the SCM_NIMPs', but this will not be starting
before January, 15th: Now I'm heading off to prepare for my skiing
vacation next week.
So long,
Dirk Herrmann