From: Darrick J. Wong Date: Mon, 15 Dec 2014 17:26:57 +0000 (-0500) Subject: libext2fs: speed up the max extent depth api call X-Git-Tag: v1.43-WIP-2015-05-18~101 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=413b5c76d830ac780680c53861e0e954dbd99532;p=tools%2Fe2fsprogs.git libext2fs: speed up the max extent depth api call The maximum extent tree depth really only depends on the filesystem block size, so cache the last result if possible. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c index b1130f6..19f38fd 100644 --- a/lib/ext2fs/extent.c +++ b/lib/ext2fs/extent.c @@ -1725,9 +1725,16 @@ size_t ext2fs_max_extent_depth(ext2_extent_handle_t handle) size_t extents_per_block = (handle->fs->blocksize - sizeof(struct ext3_extent_header)) / sizeof(struct ext3_extent); + static unsigned int last_blocksize = 0; + static size_t last_result = 0; - return 1 + ((ul_log2(EXT_MAX_EXTENT_LBLK) - ul_log2(iblock_extents)) / + if (last_blocksize && last_blocksize == handle->fs->blocksize) + return last_result; + + last_result = 1 + ((ul_log2(EXT_MAX_EXTENT_LBLK) - ul_log2(iblock_extents)) / ul_log2(extents_per_block)); + last_blocksize = handle->fs->blocksize; + return last_result; } #ifdef DEBUG