提交 f4afb4f4 编写于 作者: T Theodore Ts'o

ext4: optimize test_root()

The test_root() function could potentially loop forever due to
overflow issues.  So rewrite test_root() to avoid this issue; as a
bonus, it is 38% faster when benchmarked via a test loop:

int main(int argc, char **argv)
{
	int  i;

	for (i = 0; i < 1 << 24; i++) {
		if (test_root(i, 7))
			printf("%d\n", i);
	}
}
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 2f2e09eb
...@@ -682,11 +682,15 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) ...@@ -682,11 +682,15 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
static inline int test_root(ext4_group_t a, int b) static inline int test_root(ext4_group_t a, int b)
{ {
int num = b; while (1) {
if (a < b)
while (a > num) return 0;
num *= b; if (a == b)
return num == a; return 1;
if ((a % b) != 0)
return 0;
a = a / b;
}
} }
static int ext4_group_sparse(ext4_group_t group) static int ext4_group_sparse(ext4_group_t group)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册