chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] another proposal to modify runtime.c


From: Jörg F . Wittenberger
Subject: [Chicken-users] another proposal to modify runtime.c
Date: 28 Sep 2011 13:41:03 +0200

I can't resist to propose another minor code improvement.

For this one I even recall where I learned the trick: early in my CS
studies, we been taken to analyse how we could do better than the
straight forward implementation of double linked lists.
(Which would be the implementation of e.g., the finalizer_list
in runtime.c)

The idea is: unlinking requires too many conditionals.
The solution would be: you don't want to keep a pointer to the list
elements (which in case of the empty list would be NULL) as root.
Instead you use a static list node (thereby wasting the unused memory
for the payload).  As end-of-list marker you don't use NULL, but
the address of that root node.  You initialize the root nodes
previous and next to the address of the root node.

Now you can save all those conditionals.  Unlinking is turned into
two straight forward updates of the previous and next pointers
handing on the corresponding fields of the node.

Saves a few line, conditional and looks IMHO more clever.
Though I'm biased by the abovementioned history.

Find the diff attached.

/Jörg


Attachment: finalizer.diff
Description: finalizer.diff


reply via email to

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