diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2016-05-19 10:54:39 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-06-01 14:56:56 +0200 |
commit | 6f508a01f58d4e349af7dcf1da3dce6bfa3acbb9 (patch) | |
tree | 72d44a7c26f5e69f4fccf0588006c7ff6dc9d7d9 | |
parent | 7c43be8b578ba0133f18beb20d46c68e0225f941 (diff) |
btrfs-progs: Return earlier for previous item
Follow kernel code to return earlier for btrfs_previous_item() function.
Before this patch, btrfs_previous_item() doesn't use its min_objectid to
exit, this makes caller to check key to exit, and if caller doesn't
check, it will iterate all previous item.
This patch will check min_objectid and type, to early return and save
some time.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | ctree.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -2880,6 +2880,7 @@ int btrfs_previous_item(struct btrfs_root *root, { struct btrfs_key found_key; struct extent_buffer *leaf; + u32 nritems; int ret; while(1) { @@ -2891,9 +2892,20 @@ int btrfs_previous_item(struct btrfs_root *root, path->slots[0]--; } leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); + if (nritems == 0) + return 1; + if (path->slots[0] == nritems) + path->slots[0]--; + btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]); + if (found_key.objectid < min_objectid) + break; if (found_key.type == type) return 0; + if (found_key.objectid == min_objectid && + found_key.type < type) + break; } return 1; } |