diff options
author | Christoph Hellwig <hch@lst.de> | 2011-07-08 08:36:05 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2011-07-08 08:36:05 -0400 |
commit | 69ef921b55cc3788d1d2a27b33b27d04acd0090a (patch) | |
tree | bcc7c1f4b7f15628f122dfdb96f8d4d37f587e92 /fs/xfs/xfs_da_btree.c | |
parent | 218106a1104c598011e5df9d9aac7e0416be03e6 (diff) |
xfs: byteswap constants instead of variables
Micro-optimize various comparisms by always byteswapping the constant
instead of the variable, which allows to do the swap at compile instead
of runtime.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/xfs_da_btree.c')
-rw-r--r-- | fs/xfs/xfs_da_btree.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/fs/xfs/xfs_da_btree.c b/fs/xfs/xfs_da_btree.c index efb906f8a9c9..18425717cbe6 100644 --- a/fs/xfs/xfs_da_btree.c +++ b/fs/xfs/xfs_da_btree.c | |||
@@ -321,11 +321,11 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
321 | ASSERT(bp != NULL); | 321 | ASSERT(bp != NULL); |
322 | node = bp->data; | 322 | node = bp->data; |
323 | oldroot = blk1->bp->data; | 323 | oldroot = blk1->bp->data; |
324 | if (be16_to_cpu(oldroot->hdr.info.magic) == XFS_DA_NODE_MAGIC) { | 324 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)) { |
325 | size = (int)((char *)&oldroot->btree[be16_to_cpu(oldroot->hdr.count)] - | 325 | size = (int)((char *)&oldroot->btree[be16_to_cpu(oldroot->hdr.count)] - |
326 | (char *)oldroot); | 326 | (char *)oldroot); |
327 | } else { | 327 | } else { |
328 | ASSERT(be16_to_cpu(oldroot->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC); | 328 | ASSERT(oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); |
329 | leaf = (xfs_dir2_leaf_t *)oldroot; | 329 | leaf = (xfs_dir2_leaf_t *)oldroot; |
330 | size = (int)((char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] - | 330 | size = (int)((char *)&leaf->ents[be16_to_cpu(leaf->hdr.count)] - |
331 | (char *)leaf); | 331 | (char *)leaf); |
@@ -352,7 +352,7 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
352 | node->hdr.count = cpu_to_be16(2); | 352 | node->hdr.count = cpu_to_be16(2); |
353 | 353 | ||
354 | #ifdef DEBUG | 354 | #ifdef DEBUG |
355 | if (be16_to_cpu(oldroot->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC) { | 355 | if (oldroot->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)) { |
356 | ASSERT(blk1->blkno >= mp->m_dirleafblk && | 356 | ASSERT(blk1->blkno >= mp->m_dirleafblk && |
357 | blk1->blkno < mp->m_dirfreeblk); | 357 | blk1->blkno < mp->m_dirfreeblk); |
358 | ASSERT(blk2->blkno >= mp->m_dirleafblk && | 358 | ASSERT(blk2->blkno >= mp->m_dirleafblk && |
@@ -384,7 +384,7 @@ xfs_da_node_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
384 | int useextra; | 384 | int useextra; |
385 | 385 | ||
386 | node = oldblk->bp->data; | 386 | node = oldblk->bp->data; |
387 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 387 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
388 | 388 | ||
389 | /* | 389 | /* |
390 | * With V2 dirs the extra block is data or freespace. | 390 | * With V2 dirs the extra block is data or freespace. |
@@ -483,8 +483,8 @@ xfs_da_node_rebalance(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, | |||
483 | node1 = node2; | 483 | node1 = node2; |
484 | node2 = tmpnode; | 484 | node2 = tmpnode; |
485 | } | 485 | } |
486 | ASSERT(be16_to_cpu(node1->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 486 | ASSERT(node1->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
487 | ASSERT(be16_to_cpu(node2->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 487 | ASSERT(node2->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
488 | count = (be16_to_cpu(node1->hdr.count) - be16_to_cpu(node2->hdr.count)) / 2; | 488 | count = (be16_to_cpu(node1->hdr.count) - be16_to_cpu(node2->hdr.count)) / 2; |
489 | if (count == 0) | 489 | if (count == 0) |
490 | return; | 490 | return; |
@@ -578,7 +578,7 @@ xfs_da_node_add(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk, | |||
578 | int tmp; | 578 | int tmp; |
579 | 579 | ||
580 | node = oldblk->bp->data; | 580 | node = oldblk->bp->data; |
581 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 581 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
582 | ASSERT((oldblk->index >= 0) && (oldblk->index <= be16_to_cpu(node->hdr.count))); | 582 | ASSERT((oldblk->index >= 0) && (oldblk->index <= be16_to_cpu(node->hdr.count))); |
583 | ASSERT(newblk->blkno != 0); | 583 | ASSERT(newblk->blkno != 0); |
584 | if (state->args->whichfork == XFS_DATA_FORK) | 584 | if (state->args->whichfork == XFS_DATA_FORK) |
@@ -714,7 +714,7 @@ xfs_da_root_join(xfs_da_state_t *state, xfs_da_state_blk_t *root_blk) | |||
714 | ASSERT(args != NULL); | 714 | ASSERT(args != NULL); |
715 | ASSERT(root_blk->magic == XFS_DA_NODE_MAGIC); | 715 | ASSERT(root_blk->magic == XFS_DA_NODE_MAGIC); |
716 | oldroot = root_blk->bp->data; | 716 | oldroot = root_blk->bp->data; |
717 | ASSERT(be16_to_cpu(oldroot->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 717 | ASSERT(oldroot->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
718 | ASSERT(!oldroot->hdr.info.forw); | 718 | ASSERT(!oldroot->hdr.info.forw); |
719 | ASSERT(!oldroot->hdr.info.back); | 719 | ASSERT(!oldroot->hdr.info.back); |
720 | 720 | ||
@@ -737,10 +737,10 @@ xfs_da_root_join(xfs_da_state_t *state, xfs_da_state_blk_t *root_blk) | |||
737 | ASSERT(bp != NULL); | 737 | ASSERT(bp != NULL); |
738 | blkinfo = bp->data; | 738 | blkinfo = bp->data; |
739 | if (be16_to_cpu(oldroot->hdr.level) == 1) { | 739 | if (be16_to_cpu(oldroot->hdr.level) == 1) { |
740 | ASSERT(be16_to_cpu(blkinfo->magic) == XFS_DIR2_LEAFN_MAGIC || | 740 | ASSERT(blkinfo->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || |
741 | be16_to_cpu(blkinfo->magic) == XFS_ATTR_LEAF_MAGIC); | 741 | blkinfo->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); |
742 | } else { | 742 | } else { |
743 | ASSERT(be16_to_cpu(blkinfo->magic) == XFS_DA_NODE_MAGIC); | 743 | ASSERT(blkinfo->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
744 | } | 744 | } |
745 | ASSERT(!blkinfo->forw); | 745 | ASSERT(!blkinfo->forw); |
746 | ASSERT(!blkinfo->back); | 746 | ASSERT(!blkinfo->back); |
@@ -776,7 +776,7 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
776 | */ | 776 | */ |
777 | blk = &state->path.blk[ state->path.active-1 ]; | 777 | blk = &state->path.blk[ state->path.active-1 ]; |
778 | info = blk->bp->data; | 778 | info = blk->bp->data; |
779 | ASSERT(be16_to_cpu(info->magic) == XFS_DA_NODE_MAGIC); | 779 | ASSERT(info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
780 | node = (xfs_da_intnode_t *)info; | 780 | node = (xfs_da_intnode_t *)info; |
781 | count = be16_to_cpu(node->hdr.count); | 781 | count = be16_to_cpu(node->hdr.count); |
782 | if (count > (state->node_ents >> 1)) { | 782 | if (count > (state->node_ents >> 1)) { |
@@ -836,7 +836,7 @@ xfs_da_node_toosmall(xfs_da_state_t *state, int *action) | |||
836 | count -= state->node_ents >> 2; | 836 | count -= state->node_ents >> 2; |
837 | count -= be16_to_cpu(node->hdr.count); | 837 | count -= be16_to_cpu(node->hdr.count); |
838 | node = bp->data; | 838 | node = bp->data; |
839 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 839 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
840 | count -= be16_to_cpu(node->hdr.count); | 840 | count -= be16_to_cpu(node->hdr.count); |
841 | xfs_da_brelse(state->args->trans, bp); | 841 | xfs_da_brelse(state->args->trans, bp); |
842 | if (count >= 0) | 842 | if (count >= 0) |
@@ -911,7 +911,7 @@ xfs_da_fixhashpath(xfs_da_state_t *state, xfs_da_state_path_t *path) | |||
911 | } | 911 | } |
912 | for (blk--, level--; level >= 0; blk--, level--) { | 912 | for (blk--, level--; level >= 0; blk--, level--) { |
913 | node = blk->bp->data; | 913 | node = blk->bp->data; |
914 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 914 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
915 | btree = &node->btree[ blk->index ]; | 915 | btree = &node->btree[ blk->index ]; |
916 | if (be32_to_cpu(btree->hashval) == lasthash) | 916 | if (be32_to_cpu(btree->hashval) == lasthash) |
917 | break; | 917 | break; |
@@ -979,8 +979,8 @@ xfs_da_node_unbalance(xfs_da_state_t *state, xfs_da_state_blk_t *drop_blk, | |||
979 | 979 | ||
980 | drop_node = drop_blk->bp->data; | 980 | drop_node = drop_blk->bp->data; |
981 | save_node = save_blk->bp->data; | 981 | save_node = save_blk->bp->data; |
982 | ASSERT(be16_to_cpu(drop_node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 982 | ASSERT(drop_node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
983 | ASSERT(be16_to_cpu(save_node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 983 | ASSERT(save_node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
984 | tp = state->args->trans; | 984 | tp = state->args->trans; |
985 | 985 | ||
986 | /* | 986 | /* |
@@ -1278,8 +1278,8 @@ xfs_da_node_order(xfs_dabuf_t *node1_bp, xfs_dabuf_t *node2_bp) | |||
1278 | 1278 | ||
1279 | node1 = node1_bp->data; | 1279 | node1 = node1_bp->data; |
1280 | node2 = node2_bp->data; | 1280 | node2 = node2_bp->data; |
1281 | ASSERT((be16_to_cpu(node1->hdr.info.magic) == XFS_DA_NODE_MAGIC) && | 1281 | ASSERT(node1->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC) && |
1282 | (be16_to_cpu(node2->hdr.info.magic) == XFS_DA_NODE_MAGIC)); | 1282 | node2->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
1283 | if ((be16_to_cpu(node1->hdr.count) > 0) && (be16_to_cpu(node2->hdr.count) > 0) && | 1283 | if ((be16_to_cpu(node1->hdr.count) > 0) && (be16_to_cpu(node2->hdr.count) > 0) && |
1284 | ((be32_to_cpu(node2->btree[0].hashval) < | 1284 | ((be32_to_cpu(node2->btree[0].hashval) < |
1285 | be32_to_cpu(node1->btree[0].hashval)) || | 1285 | be32_to_cpu(node1->btree[0].hashval)) || |
@@ -1299,7 +1299,7 @@ xfs_da_node_lasthash(xfs_dabuf_t *bp, int *count) | |||
1299 | xfs_da_intnode_t *node; | 1299 | xfs_da_intnode_t *node; |
1300 | 1300 | ||
1301 | node = bp->data; | 1301 | node = bp->data; |
1302 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 1302 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
1303 | if (count) | 1303 | if (count) |
1304 | *count = be16_to_cpu(node->hdr.count); | 1304 | *count = be16_to_cpu(node->hdr.count); |
1305 | if (!node->hdr.count) | 1305 | if (!node->hdr.count) |
@@ -1412,7 +1412,7 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |||
1412 | for (blk = &path->blk[level]; level >= 0; blk--, level--) { | 1412 | for (blk = &path->blk[level]; level >= 0; blk--, level--) { |
1413 | ASSERT(blk->bp != NULL); | 1413 | ASSERT(blk->bp != NULL); |
1414 | node = blk->bp->data; | 1414 | node = blk->bp->data; |
1415 | ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC); | 1415 | ASSERT(node->hdr.info.magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
1416 | if (forward && (blk->index < be16_to_cpu(node->hdr.count)-1)) { | 1416 | if (forward && (blk->index < be16_to_cpu(node->hdr.count)-1)) { |
1417 | blk->index++; | 1417 | blk->index++; |
1418 | blkno = be32_to_cpu(node->btree[blk->index].before); | 1418 | blkno = be32_to_cpu(node->btree[blk->index].before); |
@@ -1451,9 +1451,9 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, | |||
1451 | return(error); | 1451 | return(error); |
1452 | ASSERT(blk->bp != NULL); | 1452 | ASSERT(blk->bp != NULL); |
1453 | info = blk->bp->data; | 1453 | info = blk->bp->data; |
1454 | ASSERT(be16_to_cpu(info->magic) == XFS_DA_NODE_MAGIC || | 1454 | ASSERT(info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC) || |
1455 | be16_to_cpu(info->magic) == XFS_DIR2_LEAFN_MAGIC || | 1455 | info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) || |
1456 | be16_to_cpu(info->magic) == XFS_ATTR_LEAF_MAGIC); | 1456 | info->magic == cpu_to_be16(XFS_ATTR_LEAF_MAGIC)); |
1457 | blk->magic = be16_to_cpu(info->magic); | 1457 | blk->magic = be16_to_cpu(info->magic); |
1458 | if (blk->magic == XFS_DA_NODE_MAGIC) { | 1458 | if (blk->magic == XFS_DA_NODE_MAGIC) { |
1459 | node = (xfs_da_intnode_t *)info; | 1459 | node = (xfs_da_intnode_t *)info; |
@@ -1704,12 +1704,12 @@ xfs_da_swap_lastblock(xfs_da_args_t *args, xfs_dablk_t *dead_blknop, | |||
1704 | /* | 1704 | /* |
1705 | * Get values from the moved block. | 1705 | * Get values from the moved block. |
1706 | */ | 1706 | */ |
1707 | if (be16_to_cpu(dead_info->magic) == XFS_DIR2_LEAFN_MAGIC) { | 1707 | if (dead_info->magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)) { |
1708 | dead_leaf2 = (xfs_dir2_leaf_t *)dead_info; | 1708 | dead_leaf2 = (xfs_dir2_leaf_t *)dead_info; |
1709 | dead_level = 0; | 1709 | dead_level = 0; |
1710 | dead_hash = be32_to_cpu(dead_leaf2->ents[be16_to_cpu(dead_leaf2->hdr.count) - 1].hashval); | 1710 | dead_hash = be32_to_cpu(dead_leaf2->ents[be16_to_cpu(dead_leaf2->hdr.count) - 1].hashval); |
1711 | } else { | 1711 | } else { |
1712 | ASSERT(be16_to_cpu(dead_info->magic) == XFS_DA_NODE_MAGIC); | 1712 | ASSERT(dead_info->magic == cpu_to_be16(XFS_DA_NODE_MAGIC)); |
1713 | dead_node = (xfs_da_intnode_t *)dead_info; | 1713 | dead_node = (xfs_da_intnode_t *)dead_info; |
1714 | dead_level = be16_to_cpu(dead_node->hdr.level); | 1714 | dead_level = be16_to_cpu(dead_node->hdr.level); |
1715 | dead_hash = be32_to_cpu(dead_node->btree[be16_to_cpu(dead_node->hdr.count) - 1].hashval); | 1715 | dead_hash = be32_to_cpu(dead_node->btree[be16_to_cpu(dead_node->hdr.count) - 1].hashval); |
@@ -1768,8 +1768,8 @@ xfs_da_swap_lastblock(xfs_da_args_t *args, xfs_dablk_t *dead_blknop, | |||
1768 | if ((error = xfs_da_read_buf(tp, ip, par_blkno, -1, &par_buf, w))) | 1768 | if ((error = xfs_da_read_buf(tp, ip, par_blkno, -1, &par_buf, w))) |
1769 | goto done; | 1769 | goto done; |
1770 | par_node = par_buf->data; | 1770 | par_node = par_buf->data; |
1771 | if (unlikely( | 1771 | if (unlikely(par_node->hdr.info.magic != |
1772 | be16_to_cpu(par_node->hdr.info.magic) != XFS_DA_NODE_MAGIC || | 1772 | cpu_to_be16(XFS_DA_NODE_MAGIC) || |
1773 | (level >= 0 && level != be16_to_cpu(par_node->hdr.level) + 1))) { | 1773 | (level >= 0 && level != be16_to_cpu(par_node->hdr.level) + 1))) { |
1774 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(4)", | 1774 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(4)", |
1775 | XFS_ERRLEVEL_LOW, mp); | 1775 | XFS_ERRLEVEL_LOW, mp); |
@@ -1820,7 +1820,7 @@ xfs_da_swap_lastblock(xfs_da_args_t *args, xfs_dablk_t *dead_blknop, | |||
1820 | par_node = par_buf->data; | 1820 | par_node = par_buf->data; |
1821 | if (unlikely( | 1821 | if (unlikely( |
1822 | be16_to_cpu(par_node->hdr.level) != level || | 1822 | be16_to_cpu(par_node->hdr.level) != level || |
1823 | be16_to_cpu(par_node->hdr.info.magic) != XFS_DA_NODE_MAGIC)) { | 1823 | par_node->hdr.info.magic != cpu_to_be16(XFS_DA_NODE_MAGIC))) { |
1824 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(7)", | 1824 | XFS_ERROR_REPORT("xfs_da_swap_lastblock(7)", |
1825 | XFS_ERRLEVEL_LOW, mp); | 1825 | XFS_ERRLEVEL_LOW, mp); |
1826 | error = XFS_ERROR(EFSCORRUPTED); | 1826 | error = XFS_ERROR(EFSCORRUPTED); |
@@ -2093,7 +2093,7 @@ xfs_da_do_buf( | |||
2093 | (magic != XFS_DIR2_LEAFN_MAGIC) && | 2093 | (magic != XFS_DIR2_LEAFN_MAGIC) && |
2094 | (magic1 != XFS_DIR2_BLOCK_MAGIC) && | 2094 | (magic1 != XFS_DIR2_BLOCK_MAGIC) && |
2095 | (magic1 != XFS_DIR2_DATA_MAGIC) && | 2095 | (magic1 != XFS_DIR2_DATA_MAGIC) && |
2096 | (be32_to_cpu(free->hdr.magic) != XFS_DIR2_FREE_MAGIC), | 2096 | (free->hdr.magic != cpu_to_be32(XFS_DIR2_FREE_MAGIC)), |
2097 | mp, XFS_ERRTAG_DA_READ_BUF, | 2097 | mp, XFS_ERRTAG_DA_READ_BUF, |
2098 | XFS_RANDOM_DA_READ_BUF))) { | 2098 | XFS_RANDOM_DA_READ_BUF))) { |
2099 | trace_xfs_da_btree_corrupt(rbp->bps[0], _RET_IP_); | 2099 | trace_xfs_da_btree_corrupt(rbp->bps[0], _RET_IP_); |