sys/vfs/hammer: Add hammer_is_internal|leaf_node_elm()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 24 Aug 2015 14:11:44 +0000 (23:11 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 4 Sep 2015 16:15:16 +0000 (01:15 +0900)
commit1424c9226e2bcd3186347e187ece3dd324ef5101
tree1940c3a5f4e34f76384e3b29539ebb973fc6a46b
parent2483e5ac42137f987fd5a915657522fe49f7d624
sys/vfs/hammer: Add hammer_is_internal|leaf_node_elm()

The data structure of each elm of node::elms[63] (elms[62]
for internal node excluding boundary) is simply determined
by the type of node that contains node::elms[63].

This makes code like (A) very clear and straight forward,
but makes code like (B) not clear because what elms point
to can not be simply determined by the node type.

Adding inline functions hammer_is_internal|leaf_elm() as
shown in (C), which essentialy do the same thing, makes
code look as straight forward as (A).

There are several situations where hammer wants to find
out if the given elm is an element within an internal node,
and hammer_is_internal_elm() can make such code more clear
than using switch(elm.base.btype). These functions are only
used in btree search/iteration related code. Using these
inline functions doesn't affect performance.

Also see the next commit which is related to this and the
previous commit.

===== (A)
elm = &node->elms[i];
switch (node->type) {
case HAMMER_BTREE_TYPE_INTERNAL:  /* case matches union member */
elm->internal.subtree_offset...
break;
case HAMMER_BTREE_TYPE_LEAF:  /* case matches union member */
elm->leaf.data_offset...
break;
}
=====

===== (B)
elm = &node->elms[i];
switch (elm->base.btype) {
case HAMMER_BTREE_TYPE_INTERNAL:
case HAMMER_BTREE_TYPE_LEAF:  /* this is right but not obvious */
elm->internal.subtree_offset...
break;
case HAMMER_BTREE_TYPE_RECORD:  /* this is right but not obvious */
elm->leaf.data_offset...
break;
}
=====

===== (C)
elm = &node->elms[i];
if (hammer_is_internal_node_elm(elm)) {
elm->internal.subtree_offset...
} else {
/* or else if (hammer_is_leaf_node_elm(elm)) { */
elm->leaf.data_offset...
}
=====
sys/vfs/hammer/hammer_btree.c
sys/vfs/hammer/hammer_btree.h
sys/vfs/hammer/hammer_cursor.c
sys/vfs/hammer/hammer_reblock.c