Skip to content

Commit

Permalink
Merge pull request #118 from hygoni/optimize-is-same-object
Browse files Browse the repository at this point in the history
compiler-rt: Optimize IsSameObject()
  • Loading branch information
hygoni authored Jul 7, 2024
2 parents dfe345a + 95ed3a5 commit 86d632e
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions compiler-rt/lib/plsan/plsan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,7 @@ bool IsSameObject(Metadata *metadata, const void *x, const void *y) {
if (!metadata || !y)
return false;

if (x == y)
return true;

uptr size = metadata->GetRequestedSize();
if (size <= (1 << 15)) {
// size is always power of two if allocated from the primary
uptr a = reinterpret_cast<uptr>(x) & ~(size - 1);
uptr b = reinterpret_cast<uptr>(y) & ~(size - 1);
return a == b;
}

void *begin = allocator.GetBlockBegin(x);
if (!begin)
return false;

return begin <= y && (uptr)y < (uptr)begin + metadata->GetRequestedSize();
return (GetMetadata(y) == x);
}

u8 GetRefCount(Metadata *metadata) { return metadata->GetRefCount(); }
Expand Down

0 comments on commit 86d632e

Please sign in to comment.