tdb: Optimize tdb_find by reading less memory

Description

This MR contains a small optimization in the tdb_find function.

Instead of reading the entire struct tdb_record with tdb_rec_read(), tdb_find() now starts by reading only the tdb_record.full_hash and compare it. If it does not match the searched record, it reads the tdb_record.next value and continue the search as before. If it does match, the entire record is still read for detailed checks.

By doing this small changes, we reduce the number of bytes read/copied on each iteration, except on the matching iteration.

To maintain readability in the tdb_find() function I written the check hash part in another tdb_rec_ishash() function.

Tests

I'm not against making new tests for the tdb_rec_ishash() function but I didn't know where/how to write them (not familiar with the samba environnment).

Checklist

  • Commits have Signed-off-by: with name/author being identical to the commit author
  • (optional) This MR is just one part towards a larger feature.
  • (optional, if backport required) Bugzilla bug filed and BUG: tag added
  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Documentation updated
  • CI timeout is 3h or higher (see Settings/CICD/General pipelines/ Timeout)

Reviewer's checklist:

  • There is a test suite reasonably covering new functionality or modifications
  • Function naming, parameters, return values, types, etc., are consistent and according to README.Coding.md
  • This feature/change has adequate documentation added
  • No obvious mistakes in the code

Merge request reports

Loading