In worst case code do 8 comparison,
just add some new checks to switch check branch faster
now in worst case code do 5 comparison
Signed-off-by: Timofey Titovets <nefelim4ag@xxxxxxxxx>
---
fs/btrfs/backref.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 24865da63..2e4709e0c 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -120,25 +120,29 @@ static void ref_root_free(struct ref_root *ref_tree)
*/
static int ref_node_cmp(struct ref_node *a, struct ref_node *b)
{
- if (a->root_id < b->root_id)
- return -1;
- else if (a->root_id > b->root_id)
+ if (a->root_id != b->root_id) {
+ if (a->root_id < b->root_id)
+ return -1;
return 1;
+ }
- if (a->object_id < b->object_id)
- return -1;
- else if (a->object_id > b->object_id)
+ if (a->object_id != b->object_id) {
+ if (a->object_id < b->object_id)
+ return -1;
return 1;
+ }
- if (a->offset < b->offset)
- return -1;
- else if (a->offset > b->offset)
+ if (a->offset != b->offset) {
+ if (a->offset < b->offset)
+ return -1;
return 1;
+ }
- if (a->parent < b->parent)
- return -1;
- else if (a->parent > b->parent)
+ if (a->parent != b->parent) {
+ if (a->parent < b->parent)
+ return -1;
return 1;
+ }
return 0;
}
--
2.13.0
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html