chiark / gitweb /
collect: Reduce consing.
The old collection system made a pair of cons cells: the metadata and a
random `head'.
,--------------------------.
| |
meta | head v tail
+---+-|-+ +---+---+ +---+---+
| * | * | |nil| *-----...--->| |nil|
+-|-+---+ +---+---+ +---+---+
| ^
| |
`-----------'
But we can do better: we can squidge the head and metadata nodes
together. If we start out at
head tail
+---+---+
,-->| * |nil|
| +-|-+---+
| |
`-----'
we can just insert more items by updating (cdar head)...
head tail
+---+---+ +---+---+ +---+---+
| * | *---->| | *----...--->| |nil|
+-|-+---+ +---+---+ +---+---+
| ^
| |
`-----------------------------'