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

@@ -16,7 +16,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));
return static_cast<uint16_t>(pointer_diff(this, p));
}
public:
@@ -144,7 +144,7 @@ namespace snmalloc
Metaslab& meta = super->get_meta(this);
return is_multiple_of_sizeclass(
sizeclass_to_size(meta.sizeclass),
address_cast(this) + SLAB_SIZE - address_cast(p));
pointer_diff(p, pointer_offset(this, SLAB_SIZE)));
}
// Returns true, if it deallocation can proceed without changing any status