+/* Start with enough room for ten concurrent base classes. That
+ will be enough for most hierarchies. */
+#define BFS_WALK_INITIAL_QUEUE_SIZE 10
+
+/* Subroutine of bfs_walk; enlarges the buffer it uses for its
+ circular queue. */
+static void
+grow_bfs_bases (tree **basep, size_t *sizep, size_t *headp)
+{
+ tree *base;
+ size_t size = *sizep;
+ size_t head = *headp;
+
+ /* If the size is BFS_WALK_INITIAL_QUEUE_SIZE, the old array is on
+ the stack. */
+ if (size == BFS_WALK_INITIAL_QUEUE_SIZE)
+ {
+ base = xmalloc (size * 2 * sizeof(tree));
+ memcpy (base, *basep, size * sizeof(tree));
+ }
+ else
+ base = xrealloc (*basep, size * 2 * sizeof(tree));
+
+ *basep = base;
+ *sizep = size * 2;
+
+ /* Shift all the elements between head and the former end of the
+ array, opening up a gap between tail and head. If head==0 we
+ don't need to do anything to achieve this. */
+ if (head != 0)
+ {
+ memmove (&base[head + size], &base[head],
+ (size - head) * sizeof (tree));
+ *headp = head + size;
+ }
+}
+