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

Tomohiro Kusumi tkusumi at
Fri Sep 4 10:57:31 PDT 2015

commit 62d8972eb6d897aecb7f802edd7e79797213e19e
Author: Tomohiro Kusumi <kusumi.tomohiro at>
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
    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.
    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);
    } else {
    if (node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL) {
    } else {
    KKASSERT(node->ondisk->type == HAMMER_BTREE_TYPE_INTERNAL);

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

DragonFly BSD source repository

More information about the Commits mailing list