- if (!TDB1_DEAD(r) && hash==r->full_hash
- && key.dsize==r->key_len
- && tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
- r->key_len, tdb1_key_compare,
- NULL) == 0) {
- return rec_ptr;
+ tdb->stats.compares++;
+ if (TDB1_DEAD(r)) {
+ tdb->stats.compare_wrong_bucket++;
+ } else if (key.dsize != r->key_len) {
+ tdb->stats.compare_wrong_keylen++;
+ } else if (hash != r->full_hash) {
+ tdb->stats.compare_wrong_rechash++;
+ } else {
+ enum TDB_ERROR ecode;
+ bool matches;
+ ecode = tdb1_parse_data(tdb, key, rec_ptr + sizeof(*r),
+ r->key_len, tdb1_key_compare,
+ &matches);
+
+ if (ecode != TDB_SUCCESS) {
+ tdb->last_error = ecode;
+ return 0;
+ }
+
+ if (!matches) {
+ tdb->stats.compare_wrong_keycmp++;
+ } else {
+ return rec_ptr;
+ }