ds/address: add pointer diff function

And use it rather than open-coding subtraction of two address_cast-s.
This commit is contained in:
Nathaniel Filardo
2019-05-12 20:01:54 +01:00
parent eb2d8890de
commit 83c467eb92
5 changed files with 19 additions and 8 deletions

View File

@@ -125,8 +125,7 @@ namespace snmalloc
uint16_t pointer_to_index(void* p)
{
// Get the offset from the slab for a memory location.
return static_cast<uint16_t>(
((address_cast(p) - address_cast(this))) >> 8);
return static_cast<uint16_t>(pointer_diff(this, p) >> 8);
}
};
} // namespace snmalloc