aboutsummaryrefslogtreecommitdiff
path: root/lib/ext2fs/badblocks.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1999-11-08 22:05:04 +0000
committerTheodore Ts'o <tytso@mit.edu>1999-11-08 22:05:04 +0000
commit9b9fe8ac19db2bbd202bffd305ceee767a45f57a (patch)
tree2e6c337ae8073bd1cbf89b873438c6afef491c0d /lib/ext2fs/badblocks.c
parent643efb8a791e8b16b649643b41e02fab96d28df8 (diff)
downloade2fsprogs-9b9fe8ac19db2bbd202bffd305ceee767a45f57a.tar.gz
ChangeLog, Makefile.in, badblocks.c, freefs.c, tst_badblocks.c:
Makefile.in (tst_badblocks): Add freefs.o to the object list, since ext2fs_badblocks_list_free was moved to freefs.c. tst_badblocks.c: Use the newer badblocks API names. Add duplicate blocks to the test inputs to test dealing with adding blocks which are already in the badblocks list. badblocks.c (ext2fs_badblocks_list_add): If appending to the end of the list, use a shortcut O(1) operations instead of an O(n) operation. (Idea suggested by David Beattie.) freefs.c (ext2fs_free): Use ext2fs_badblocks_list_free() instead of badblocks_list_free(), to save a procedure call.
Diffstat (limited to 'lib/ext2fs/badblocks.c')
-rw-r--r--lib/ext2fs/badblocks.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/ext2fs/badblocks.c b/lib/ext2fs/badblocks.c
index e2f46f15..8c090794 100644
--- a/lib/ext2fs/badblocks.c
+++ b/lib/ext2fs/badblocks.c
@@ -116,6 +116,17 @@ errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, blk_t blk)
}
}
+ /*
+ * Add special case code for appending to the end of the list
+ */
+ i = bb->num-1;
+ if ((bb->num != 0) && (bb->list[i] == blk))
+ return 0;
+ if ((bb->num == 0) || (bb->list[i] < blk)) {
+ bb->list[bb->num++] = blk;
+ return 0;
+ }
+
j = bb->num;
for (i=0; i < bb->num; i++) {
if (bb->list[i] == blk)