Skip to content

Commit

Permalink
Revert mime-table optimization, partially
Browse files Browse the repository at this point in the history
Since bsearch() only compares the key itself with the other values from
the array, this optimization would never work, as compare_mime_entry()
would never be called with pointers from the mime extension table.
  • Loading branch information
lpereira committed May 12, 2024
1 parent 5342311 commit 2771ad5
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/lib/lwan-tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,8 @@ LWAN_SELF_TEST(status_codes)

static int compare_mime_entry(const void *a, const void *b)
{
static const uintptr_t begin = (uintptr_t)uncompressed_mime_entries;
static const uintptr_t end = begin + 8 * MIME_ENTRIES;
const uintptr_t pa = (uintptr_t)a;
const uintptr_t pb = (uintptr_t)b;
uint64_t exta;
uint64_t extb;

if (end - pa >= begin && end - pb >= begin) {
/* If both keys are within the uncompressed mime entries range, then
* we don't need to load from memory, just compare the pointers: they're
* all stored sequentially in memory by construction. */
exta = pa;
extb = pb;
} else {
/* These are stored in big-endian so the comparison below works
* as expected. */
exta = string_as_uint64((const char *)a);
extb = string_as_uint64((const char *)b);
}
const uint64_t exta = string_as_uint64((const char *)a);
const uint64_t extb = string_as_uint64((const char *)b);

return (exta > extb) - (exta < extb);
}
Expand Down

0 comments on commit 2771ad5

Please sign in to comment.