diff options
author | Aaron Patterson <[email protected]> | 2023-10-24 11:59:48 -0700 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2023-10-24 14:23:17 -0700 |
commit | 702b8e3107a91f1a3ca230e68a9ef4086a8869b5 (patch) | |
tree | 14f1aeabe4c4f510e05788c1245ddba3460bf517 | |
parent | ee8299864f6556926fdcf85a52b2d9080446ee81 (diff) |
golf down ancestor caching
-rw-r--r-- | shape.c | 29 |
1 files changed, 10 insertions, 19 deletions
@@ -384,29 +384,20 @@ rb_shape_alloc(ID edge_name, rb_shape_t * parent, enum shape_type type) static redblack_node_t * redblack_cache_ancestors(rb_shape_t * shape) { - if (shape->ancestor_index) { - return shape->ancestor_index; - } - else { - if (shape->parent_id == INVALID_SHAPE_ID) { - // We're at the root - return shape->ancestor_index; - } - else { - redblack_node_t * parent_index; + if (!(shape->ancestor_index || shape->parent_id == INVALID_SHAPE_ID)) { + redblack_node_t * parent_index; - parent_index = redblack_cache_ancestors(rb_shape_get_parent(shape)); + parent_index = redblack_cache_ancestors(rb_shape_get_parent(shape)); - if (shape->type == SHAPE_IVAR) { - shape->ancestor_index = redblack_insert(parent_index, shape->edge_name, shape); - } - else { - shape->ancestor_index = parent_index; - } - - return shape->ancestor_index; + if (shape->type == SHAPE_IVAR) { + shape->ancestor_index = redblack_insert(parent_index, shape->edge_name, shape); + } + else { + shape->ancestor_index = parent_index; } } + + return shape->ancestor_index; } #else static redblack_node_t * |