guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scm_sloppy_memq


From: Dirk Herrmann
Subject: Re: scm_sloppy_memq
Date: Fri, 1 Dec 2000 11:14:14 +0100 (MET)

On Thu, 30 Nov 2000, Mikael Djurfeldt wrote:

> I saw that you have replaced the use of scm_sloppy_memq in some places
> by scm_memq.  (Did you do the same with scm_sloppy_assq?)
> 
> Why did you do this?
>
> The name "scm_sloppy_memq" and perhaps some of its semantics
> (returning SCM_EOL) could be discussed, but I think we should have
> efficient C-level versions of scm_memq and scm_assq for internal use
> in the implementation of libguile.

First, I admit that I did not look very closely into the performance
consequences of the change, because some of the posts regarding goops gave
me the impression that up to now goops is not performance optimized anyway
yet.  Maybe that was a misunderstanding, but even then, I could have been
more careful there - sorry.  However, my plan was to do some goops cleanup
anyway, bringing it closer to guile's today API, and then looking into
such things more closely.

But, there is something about scm_sloppy_memq which we should think about,
before re-introducing a function like that:  The (now deprecated) current
version of scm_sloppy_memq will accept any object, in particular lists and
improper lists as argument.  This means, if you see a call to
scm_sloppy_memq, this does not give you any assertions about the type of
the parameter.  If we would like to have such a function in the API at
all, we should have two versions of scm_sloppy_memq, one which accepts any
object, as it is now, and one which assumes that the argument is a proper
list.

For the goops case, the argument is known to be a proper list, which means
a loop that scans the list can look like follows:
  for (i = lst; !SCM_NULLP (i); i = SCM_CDR (i))
    if (SCM_EQ_P (SCM_CAR (i), x)) ...
which has the benefit that there _is_ some implicit type checking:  If the
argument is not a proper list, the code will crash.  Obviously, such a
function should not be exported to the scheme level.

For the other case, where the argument can be anything, the scanning of
the list works as follows:
  for (i = obj; SCM_CONSP (i); i = SCM_CDR (i))
    if (SCM_EQ_P (SCM_CAR (i), x)) ...
which will work in any case.  Such a function could potentially be
exported to the scheme level, since it can't crash, but I wonder if this
is a good idea.

An optimized goops should use the first solution, because it offers some
type checking for free.  Using the current scm_sloppy_memq, bugs in goops
due to ill-constructed lists will take longer to get detected.

Since the functions are quite trivial, it could also be an option to use
static functions, potentially as inline functions.

Dirk Herrmann




reply via email to

[Prev in Thread] Current Thread [Next in Thread]