Skip to contentSkip to conversation

befs (3/5): binary search microoptimisation

PATCH New Sergey S. Kostyliov 1 participant 1 message May 13, 2004 Befs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 befs (3/5): binary search microoptimisation

Move value initialisation out of the loop body.

===== fs/befs/btree.c 1.6 vs edited =====

fs/befs/btree.c +3 -1
@@ -372,12 +372,12 @@
 		thiskey = befs_bt_get_key(sb, node, mid, &keylen);
 		eq = befs_compare_strings(thiskey, keylen, findkey,
 					  findkey_len);
-		*value = fs64_to_cpu(sb, valarray[mid]);
 
 		if (eq == 0) {
 			befs_debug(sb, "<--- befs_find_key() found %s at %d",
 				   thiskey, mid);
 
+			*value = fs64_to_cpu(sb, valarray[mid]);
 			return BEFS_BT_MATCH;
 		}
 		if (eq > 0)
@@ -387,6 +387,8 @@
 	}
 	if (eq < 0)
 		*value = fs64_to_cpu(sb, valarray[mid + 1]);
+	else
+		*value = fs64_to_cpu(sb, valarray[mid]);
 	befs_debug(sb, "<--- befs_find_key() found %s at %d", thiskey, mid);
 	return BEFS_BT_PARMATCH;
 }
Signature · 3 lines
                   Best regards,
                   Sergey S. Kostyliov <[email protected]>
                   Public PGP key: http://sysadminday.org.ru/rathamahata.asc