libext2fs: optimize ext2fs_bg_has_super()

Reduce the CPU time needed when checking whether a block group has a
sparse superblock.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 973c2a2..3582a0c 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -20,12 +20,12 @@
 #include "ext2_fs.h"
 #include "ext2fsP.h"
 
-static int test_root(int a, int b)
+static int test_root(unsigned int a, unsigned int b)
 {
-	if (a == 0)
-		return 1;
 	while (1) {
-		if (a == 1)
+		if (a < b)
+			return 0;
+		if (a == b)
 			return 1;
 		if (a % b)
 			return 0;
@@ -33,14 +33,15 @@
 	}
 }
 
-int ext2fs_bg_has_super(ext2_filsys fs, int group_block)
+int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group)
 {
 	if (!(fs->super->s_feature_ro_compat &
-	      EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
+	      EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) || group <= 1)
 		return 1;
-
-	if (test_root(group_block, 3) || (test_root(group_block, 5)) ||
-	    test_root(group_block, 7))
+	if (!(group & 1))
+		return 0;
+	if (test_root(group, 3) || (test_root(group, 5)) ||
+	    test_root(group, 7))
 		return 1;
 
 	return 0;
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 93c8360..326d5c1 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -911,7 +911,7 @@
 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
 extern errcode_t ext2fs_flush(ext2_filsys fs);
 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
-extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
+extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
 				    dgrp_t group,
 				    blk64_t *ret_super_blk,