]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: optimize rb_get_bmap_range()
authorTheodore Ts'o <tytso@mit.edu>
Sat, 24 Nov 2012 23:35:42 +0000 (18:35 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 29 Nov 2012 00:01:51 +0000 (19:01 -0500)
This simplifies the rb_get_bmap_range() function and speeds it up for
the case where most of the bitmap is zero.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
lib/ext2fs/blkmap64_rb.c

index 0fc7c57edbbaf461c3da835d7d138031b760c8a3..eb56c856691b1c5e7067834797e5d41f9b46cf67 100644 (file)
@@ -741,32 +741,23 @@ static errcode_t rb_get_bmap_range(ext2fs_generic_bitmap bitmap,
                        break;
        }
 
-       pos = start;
+       memset(out, 0, (num + 7) >> 3);
+
        for (; parent != NULL; parent = next) {
                next = ext2fs_rb_next(parent);
                ext = ext2fs_rb_entry(parent, struct bmap_rb_extent, node);
 
-               while (((pos - start) < num) &&
-                       (pos < ext->start)) {
-                       ext2fs_fast_clear_bit64((pos - start), out);
-                       pos++;
-               }
-
-               if ((pos - start) >= num)
-                       return 0;
+               pos = ext->start;
+               if (pos < start)
+                       pos = start;
 
-               while (((pos - start) < num) &&
-                       (pos < (ext->start + ext->count))) {
+               while (pos < (ext->start + ext->count)) {
+                       if ((pos - start) >= num)
+                               return 0;
                        ext2fs_fast_set_bit64((pos - start), out);
                        pos++;
                }
        }
-
-       while ((pos - start) < num) {
-               ext2fs_fast_clear_bit64((pos - start), out);
-               pos++;
-       }
-
        return 0;
 }