collect: Reduce consing.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 27 Apr 2006 10:57:40 +0000 (11:57 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 29 Apr 2006 10:15:53 +0000 (11:15 +0100)
commita721f2f26b71a60ee0aebb9c7d28f06c593ef2e4
tree0de79eb8b63fbcdccd036873130055114de9f981
parentb3bc37457df55c92cabc8aeeb42bc67d3fb8af12
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|
  +-|-+---+   +---+---+         +---+---+
    |                             ^
    |                             |
    `-----------------------------'
collect.lisp