]> granicus.if.org Git - graphviz/commit
simplify bitarray API to assume arrays are only resized at construction time
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 12 Jan 2022 04:35:16 +0000 (20:35 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 12 Jan 2022 15:50:35 +0000 (07:50 -0800)
commit458eb0a4acb25db5e5e911481ea16fccc5973cf5
treed1802bd8a98b859b9b187da8a17521ffdca0aff2
parent3b828a22ef0886ba3d6c074c238135670b791f5b
simplify bitarray API to assume arrays are only resized at construction time

The bit array API was written to allow arbitrary growing or shrinking of an
array after its construction, while maintaining its content. After fully rolling
it out, it turns out Graphviz only ever creates such arrays once at a fixed size
and then uses them until free. Carrying a more generic API than was necessary
had a number of negative consequences:

  1. `bitarray_resize` was more complicated than it needed to be, in order to
     cope with an arbitrary initial size of the input array.

  2. `bitarray_resize` used `realloc;memset` instead of the more efficient
     `calloc` because it was assuming the caller needed to maintain the original
     content.

  3. `bitarray_resize` performed a “loose” allocation with the capacity of the
     backing buffer larger than the size of the array itself, assuming that
     amortizing allocation costs across repeated resizes was a relevant concern.
     Dropping this and making the allocation “tight” not only reduces heap
     pressure, but allows dropping the `.capacity` member.

  4. `bitarray_array_resize_or_exit` had a more awkward calling convention than
     necessary, as exemplified by how it is streamlined in this commit.

As such, this change not only simplifies the code but also reduces memory usage.
lib/cgraph/bitarray.h
lib/neatogen/dijkstra.c
lib/neatogen/neatoinit.c
lib/neatogen/sgd.c