Skip to content

Commit

Permalink
Only type-check simdhash instances in debug builds
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 13, 2024
1 parent 850c6bc commit 157380e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/native/containers/dn-simdhash-specialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,19 @@ dn_simdhash_meta_t DN_SIMDHASH_T_META = {
};


static DN_FORCEINLINE(uint8_t)
static DN_FORCEINLINE(void)
check_self (DN_SIMDHASH_T_PTR self)
{
#ifdef NDEBUG
// In release builds, just nullcheck. Checking meta adds measurable overhead.
dn_simdhash_assert(self);
#else
// Verifies both that the self-ptr is non-null and that the meta pointer matches
// what it should be. This detects passing the wrong kind of simdhash_t pointer
// to one of the APIs, since C doesn't have fully type-safe pointers.
uint8_t ok = self && (self->meta == &DN_SIMDHASH_T_META);
dn_simdhash_assert(ok);
return ok;
#endif
}


Expand Down

0 comments on commit 157380e

Please sign in to comment.