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_dir2_leaf.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_dir2_leaf.c')
-rw-r--r-- | fs/xfs/xfs_dir2_leaf.c | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c index 5d2651f1c759..d629b888ca28 100644 --- a/fs/xfs/xfs_dir2_leaf.c +++ b/fs/xfs/xfs_dir2_leaf.c | |||
@@ -201,8 +201,8 @@ xfs_dir2_leaf_find_entry( | |||
201 | */ | 201 | */ |
202 | for (lowstale = index - 1; | 202 | for (lowstale = index - 1; |
203 | lowstale >= 0 && | 203 | lowstale >= 0 && |
204 | be32_to_cpu(leaf->ents[lowstale].address) != | 204 | leaf->ents[lowstale].address != |
205 | XFS_DIR2_NULL_DATAPTR; | 205 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR); |
206 | lowstale--) | 206 | lowstale--) |
207 | continue; | 207 | continue; |
208 | 208 | ||
@@ -213,8 +213,8 @@ xfs_dir2_leaf_find_entry( | |||
213 | */ | 213 | */ |
214 | for (highstale = index; | 214 | for (highstale = index; |
215 | highstale < be16_to_cpu(leaf->hdr.count) && | 215 | highstale < be16_to_cpu(leaf->hdr.count) && |
216 | be32_to_cpu(leaf->ents[highstale].address) != | 216 | leaf->ents[highstale].address != |
217 | XFS_DIR2_NULL_DATAPTR && | 217 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR) && |
218 | (lowstale < 0 || | 218 | (lowstale < 0 || |
219 | index - lowstale - 1 >= highstale - index); | 219 | index - lowstale - 1 >= highstale - index); |
220 | highstale++) | 220 | highstale++) |
@@ -228,8 +228,8 @@ xfs_dir2_leaf_find_entry( | |||
228 | (highstale == be16_to_cpu(leaf->hdr.count) || | 228 | (highstale == be16_to_cpu(leaf->hdr.count) || |
229 | index - lowstale - 1 < highstale - index)) { | 229 | index - lowstale - 1 < highstale - index)) { |
230 | ASSERT(index - lowstale - 1 >= 0); | 230 | ASSERT(index - lowstale - 1 >= 0); |
231 | ASSERT(be32_to_cpu(leaf->ents[lowstale].address) == | 231 | ASSERT(leaf->ents[lowstale].address == |
232 | XFS_DIR2_NULL_DATAPTR); | 232 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)); |
233 | 233 | ||
234 | /* | 234 | /* |
235 | * Copy entries up to cover the stale entry and make room | 235 | * Copy entries up to cover the stale entry and make room |
@@ -251,8 +251,8 @@ xfs_dir2_leaf_find_entry( | |||
251 | * The high one is better, so use that one. | 251 | * The high one is better, so use that one. |
252 | */ | 252 | */ |
253 | ASSERT(highstale - index >= 0); | 253 | ASSERT(highstale - index >= 0); |
254 | ASSERT(be32_to_cpu(leaf->ents[highstale].address) == | 254 | ASSERT(leaf->ents[highstale].address == |
255 | XFS_DIR2_NULL_DATAPTR); | 255 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)); |
256 | 256 | ||
257 | /* | 257 | /* |
258 | * Copy entries down to cover the stale entry and make room for the | 258 | * Copy entries down to cover the stale entry and make room for the |
@@ -342,7 +342,7 @@ xfs_dir2_leaf_addname( | |||
342 | continue; | 342 | continue; |
343 | i = xfs_dir2_dataptr_to_db(mp, be32_to_cpu(lep->address)); | 343 | i = xfs_dir2_dataptr_to_db(mp, be32_to_cpu(lep->address)); |
344 | ASSERT(i < be32_to_cpu(ltp->bestcount)); | 344 | ASSERT(i < be32_to_cpu(ltp->bestcount)); |
345 | ASSERT(be16_to_cpu(bestsp[i]) != NULLDATAOFF); | 345 | ASSERT(bestsp[i] != cpu_to_be16(NULLDATAOFF)); |
346 | if (be16_to_cpu(bestsp[i]) >= length) { | 346 | if (be16_to_cpu(bestsp[i]) >= length) { |
347 | use_block = i; | 347 | use_block = i; |
348 | break; | 348 | break; |
@@ -356,7 +356,8 @@ xfs_dir2_leaf_addname( | |||
356 | /* | 356 | /* |
357 | * Remember a block we see that's missing. | 357 | * Remember a block we see that's missing. |
358 | */ | 358 | */ |
359 | if (be16_to_cpu(bestsp[i]) == NULLDATAOFF && use_block == -1) | 359 | if (bestsp[i] == cpu_to_be16(NULLDATAOFF) && |
360 | use_block == -1) | ||
360 | use_block = i; | 361 | use_block = i; |
361 | else if (be16_to_cpu(bestsp[i]) >= length) { | 362 | else if (be16_to_cpu(bestsp[i]) >= length) { |
362 | use_block = i; | 363 | use_block = i; |
@@ -377,7 +378,7 @@ xfs_dir2_leaf_addname( | |||
377 | * Now kill use_block if it refers to a missing block, so we | 378 | * Now kill use_block if it refers to a missing block, so we |
378 | * can use it as an indication of allocation needed. | 379 | * can use it as an indication of allocation needed. |
379 | */ | 380 | */ |
380 | if (use_block != -1 && be16_to_cpu(bestsp[use_block]) == NULLDATAOFF) | 381 | if (use_block != -1 && bestsp[use_block] == cpu_to_be16(NULLDATAOFF)) |
381 | use_block = -1; | 382 | use_block = -1; |
382 | /* | 383 | /* |
383 | * If we don't have enough free bytes but we can make enough | 384 | * If we don't have enough free bytes but we can make enough |
@@ -590,7 +591,7 @@ xfs_dir2_leaf_check( | |||
590 | 591 | ||
591 | leaf = bp->data; | 592 | leaf = bp->data; |
592 | mp = dp->i_mount; | 593 | mp = dp->i_mount; |
593 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC); | 594 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); |
594 | /* | 595 | /* |
595 | * This value is not restrictive enough. | 596 | * This value is not restrictive enough. |
596 | * Should factor in the size of the bests table as well. | 597 | * Should factor in the size of the bests table as well. |
@@ -610,7 +611,7 @@ xfs_dir2_leaf_check( | |||
610 | if (i + 1 < be16_to_cpu(leaf->hdr.count)) | 611 | if (i + 1 < be16_to_cpu(leaf->hdr.count)) |
611 | ASSERT(be32_to_cpu(leaf->ents[i].hashval) <= | 612 | ASSERT(be32_to_cpu(leaf->ents[i].hashval) <= |
612 | be32_to_cpu(leaf->ents[i + 1].hashval)); | 613 | be32_to_cpu(leaf->ents[i + 1].hashval)); |
613 | if (be32_to_cpu(leaf->ents[i].address) == XFS_DIR2_NULL_DATAPTR) | 614 | if (leaf->ents[i].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) |
614 | stale++; | 615 | stale++; |
615 | } | 616 | } |
616 | ASSERT(be16_to_cpu(leaf->hdr.stale) == stale); | 617 | ASSERT(be16_to_cpu(leaf->hdr.stale) == stale); |
@@ -639,7 +640,8 @@ xfs_dir2_leaf_compact( | |||
639 | * Compress out the stale entries in place. | 640 | * Compress out the stale entries in place. |
640 | */ | 641 | */ |
641 | for (from = to = 0, loglow = -1; from < be16_to_cpu(leaf->hdr.count); from++) { | 642 | for (from = to = 0, loglow = -1; from < be16_to_cpu(leaf->hdr.count); from++) { |
642 | if (be32_to_cpu(leaf->ents[from].address) == XFS_DIR2_NULL_DATAPTR) | 643 | if (leaf->ents[from].address == |
644 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) | ||
643 | continue; | 645 | continue; |
644 | /* | 646 | /* |
645 | * Only actually copy the entries that are different. | 647 | * Only actually copy the entries that are different. |
@@ -696,7 +698,8 @@ xfs_dir2_leaf_compact_x1( | |||
696 | */ | 698 | */ |
697 | for (lowstale = index - 1; | 699 | for (lowstale = index - 1; |
698 | lowstale >= 0 && | 700 | lowstale >= 0 && |
699 | be32_to_cpu(leaf->ents[lowstale].address) != XFS_DIR2_NULL_DATAPTR; | 701 | leaf->ents[lowstale].address != |
702 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR); | ||
700 | lowstale--) | 703 | lowstale--) |
701 | continue; | 704 | continue; |
702 | /* | 705 | /* |
@@ -705,7 +708,8 @@ xfs_dir2_leaf_compact_x1( | |||
705 | */ | 708 | */ |
706 | for (highstale = index; | 709 | for (highstale = index; |
707 | highstale < be16_to_cpu(leaf->hdr.count) && | 710 | highstale < be16_to_cpu(leaf->hdr.count) && |
708 | be32_to_cpu(leaf->ents[highstale].address) != XFS_DIR2_NULL_DATAPTR && | 711 | leaf->ents[highstale].address != |
712 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR) && | ||
709 | (lowstale < 0 || index - lowstale > highstale - index); | 713 | (lowstale < 0 || index - lowstale > highstale - index); |
710 | highstale++) | 714 | highstale++) |
711 | continue; | 715 | continue; |
@@ -729,7 +733,8 @@ xfs_dir2_leaf_compact_x1( | |||
729 | if (index == from) | 733 | if (index == from) |
730 | newindex = to; | 734 | newindex = to; |
731 | if (from != keepstale && | 735 | if (from != keepstale && |
732 | be32_to_cpu(leaf->ents[from].address) == XFS_DIR2_NULL_DATAPTR) { | 736 | leaf->ents[from].address == |
737 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) { | ||
733 | if (from == to) | 738 | if (from == to) |
734 | *lowlogp = to; | 739 | *lowlogp = to; |
735 | continue; | 740 | continue; |
@@ -1207,7 +1212,7 @@ xfs_dir2_leaf_log_bests( | |||
1207 | xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ | 1212 | xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ |
1208 | 1213 | ||
1209 | leaf = bp->data; | 1214 | leaf = bp->data; |
1210 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC); | 1215 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); |
1211 | ltp = xfs_dir2_leaf_tail_p(tp->t_mountp, leaf); | 1216 | ltp = xfs_dir2_leaf_tail_p(tp->t_mountp, leaf); |
1212 | firstb = xfs_dir2_leaf_bests_p(ltp) + first; | 1217 | firstb = xfs_dir2_leaf_bests_p(ltp) + first; |
1213 | lastb = xfs_dir2_leaf_bests_p(ltp) + last; | 1218 | lastb = xfs_dir2_leaf_bests_p(ltp) + last; |
@@ -1230,8 +1235,8 @@ xfs_dir2_leaf_log_ents( | |||
1230 | xfs_dir2_leaf_t *leaf; /* leaf structure */ | 1235 | xfs_dir2_leaf_t *leaf; /* leaf structure */ |
1231 | 1236 | ||
1232 | leaf = bp->data; | 1237 | leaf = bp->data; |
1233 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC || | 1238 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) || |
1234 | be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC); | 1239 | leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); |
1235 | firstlep = &leaf->ents[first]; | 1240 | firstlep = &leaf->ents[first]; |
1236 | lastlep = &leaf->ents[last]; | 1241 | lastlep = &leaf->ents[last]; |
1237 | xfs_da_log_buf(tp, bp, (uint)((char *)firstlep - (char *)leaf), | 1242 | xfs_da_log_buf(tp, bp, (uint)((char *)firstlep - (char *)leaf), |
@@ -1249,8 +1254,8 @@ xfs_dir2_leaf_log_header( | |||
1249 | xfs_dir2_leaf_t *leaf; /* leaf structure */ | 1254 | xfs_dir2_leaf_t *leaf; /* leaf structure */ |
1250 | 1255 | ||
1251 | leaf = bp->data; | 1256 | leaf = bp->data; |
1252 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC || | 1257 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) || |
1253 | be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC); | 1258 | leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); |
1254 | xfs_da_log_buf(tp, bp, (uint)((char *)&leaf->hdr - (char *)leaf), | 1259 | xfs_da_log_buf(tp, bp, (uint)((char *)&leaf->hdr - (char *)leaf), |
1255 | (uint)(sizeof(leaf->hdr) - 1)); | 1260 | (uint)(sizeof(leaf->hdr) - 1)); |
1256 | } | 1261 | } |
@@ -1269,7 +1274,7 @@ xfs_dir2_leaf_log_tail( | |||
1269 | 1274 | ||
1270 | mp = tp->t_mountp; | 1275 | mp = tp->t_mountp; |
1271 | leaf = bp->data; | 1276 | leaf = bp->data; |
1272 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAF1_MAGIC); | 1277 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); |
1273 | ltp = xfs_dir2_leaf_tail_p(mp, leaf); | 1278 | ltp = xfs_dir2_leaf_tail_p(mp, leaf); |
1274 | xfs_da_log_buf(tp, bp, (uint)((char *)ltp - (char *)leaf), | 1279 | xfs_da_log_buf(tp, bp, (uint)((char *)ltp - (char *)leaf), |
1275 | (uint)(mp->m_dirblksize - 1)); | 1280 | (uint)(mp->m_dirblksize - 1)); |
@@ -1570,7 +1575,7 @@ xfs_dir2_leaf_removename( | |||
1570 | * Look for the last active entry (i). | 1575 | * Look for the last active entry (i). |
1571 | */ | 1576 | */ |
1572 | for (i = db - 1; i > 0; i--) { | 1577 | for (i = db - 1; i > 0; i--) { |
1573 | if (be16_to_cpu(bestsp[i]) != NULLDATAOFF) | 1578 | if (bestsp[i] != cpu_to_be16(NULLDATAOFF)) |
1574 | break; | 1579 | break; |
1575 | } | 1580 | } |
1576 | /* | 1581 | /* |
@@ -1740,7 +1745,7 @@ xfs_dir2_leaf_trim_data( | |||
1740 | { | 1745 | { |
1741 | struct xfs_dir2_data_hdr *hdr = dbp->data; | 1746 | struct xfs_dir2_data_hdr *hdr = dbp->data; |
1742 | 1747 | ||
1743 | ASSERT(be32_to_cpu(hdr->magic) == XFS_DIR2_DATA_MAGIC); | 1748 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC)); |
1744 | ASSERT(be16_to_cpu(hdr->bestfree[0].length) == | 1749 | ASSERT(be16_to_cpu(hdr->bestfree[0].length) == |
1745 | mp->m_dirblksize - (uint)sizeof(*hdr)); | 1750 | mp->m_dirblksize - (uint)sizeof(*hdr)); |
1746 | ASSERT(db == be32_to_cpu(ltp->bestcount) - 1); | 1751 | ASSERT(db == be32_to_cpu(ltp->bestcount) - 1); |
@@ -1850,7 +1855,7 @@ xfs_dir2_node_to_leaf( | |||
1850 | return 0; | 1855 | return 0; |
1851 | lbp = state->path.blk[0].bp; | 1856 | lbp = state->path.blk[0].bp; |
1852 | leaf = lbp->data; | 1857 | leaf = lbp->data; |
1853 | ASSERT(be16_to_cpu(leaf->hdr.info.magic) == XFS_DIR2_LEAFN_MAGIC); | 1858 | ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); |
1854 | /* | 1859 | /* |
1855 | * Read the freespace block. | 1860 | * Read the freespace block. |
1856 | */ | 1861 | */ |
@@ -1859,7 +1864,7 @@ xfs_dir2_node_to_leaf( | |||
1859 | return error; | 1864 | return error; |
1860 | } | 1865 | } |
1861 | free = fbp->data; | 1866 | free = fbp->data; |
1862 | ASSERT(be32_to_cpu(free->hdr.magic) == XFS_DIR2_FREE_MAGIC); | 1867 | ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC)); |
1863 | ASSERT(!free->hdr.firstdb); | 1868 | ASSERT(!free->hdr.firstdb); |
1864 | 1869 | ||
1865 | /* | 1870 | /* |