git: sys/vfs/hammer: Add hammer_is_internal|leaf_node_elm()

Tomohiro Kusumi tkusumi at crater.dragonflybsd.org
Fri Sep 4 10:57:30 PDT 2015


commit 1424c9226e2bcd3186347e187ece3dd324ef5101
Author: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
Date:   Mon Aug 24 23:11:44 2015 +0900

    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...
    }
    =====

Summary of changes:
 sys/vfs/hammer/hammer_btree.c   | 29 +++++++++--------------------
 sys/vfs/hammer/hammer_btree.h   | 31 +++++++++++++++++++++++++++++++
 sys/vfs/hammer/hammer_cursor.c  | 11 +++--------
 sys/vfs/hammer/hammer_reblock.c |  1 +
 4 files changed, 44 insertions(+), 28 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1424c9226e2bcd3186347e187ece3dd324ef5101


-- 
DragonFly BSD source repository



More information about the Commits mailing list