git: sys/vfs/hammer: Remove redundant elm type check [2/2]

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


commit 62d8972eb6d897aecb7f802edd7e79797213e19e
Author: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
Date:   Sat Aug 29 17:08:50 2015 +0900

    sys/vfs/hammer: Remove redundant elm type check [2/2]
    
    The following code(A) in hammer_cursor_down() is redundant.
    It works the same with or without if/else conditional.
    
    hammer_is_internal_node_elm(elm) == 1
    and
    node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL
    are essentially the same thing from the way hammer's ondisk
    data structure is designed.
    
    If above is not true, then it ends up calling panic().
    Then (A) can be written like (B), and (B) can be written
    like (C) since it's either panic or not panic anyway.
    
    Also the way (C) looks is natural given that the purpose
    of this function is to move the cursor downward to one of
    its children. It must be an internal (non-leaf) to be able
    to go down.
    
    =====(A)
    if (hammer_is_internal_node_elm(elm)) {
    	/* below never fails if above is true, and */
    	/* above would have never failed if below is true */
    	KKASSERT(node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL);
    	go_down();
    } else {
    	panic();
    }
    =====
    
    =====(B)
    if (node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL) {
    	go_down();
    } else {
    	panic();
    }
    =====
    
    =====(C)
    KKASSERT(node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL);
    go_down();
    =====

Summary of changes:
 sys/vfs/hammer/hammer_cursor.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/62d8972eb6d897aecb7f802edd7e79797213e19e


-- 
DragonFly BSD source repository



More information about the Commits mailing list