diff options
author | Kostya Serebryany <kcc@google.com> | 2016-08-09 20:54:50 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-08-09 20:54:50 +0000 |
commit | 64b05038ff88929ef1a49a389f8e1d7c92a09bc6 (patch) | |
tree | 665b9e1749082cc167f465f74217beccb7f98d3f /lib | |
parent | 055eba88d72e693a75bae2535c304d3428fb9c93 (diff) |
[sanitizer] minor refactoring in the allocator, NFC
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@278163 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator_local_cache.h | 3 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator_primary32.h | 8 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_allocator_primary64.h | 6 |
3 files changed, 8 insertions, 9 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_local_cache.h b/lib/sanitizer_common/sanitizer_allocator_local_cache.h index a63a50693..38d63a555 100644 --- a/lib/sanitizer_common/sanitizer_allocator_local_cache.h +++ b/lib/sanitizer_common/sanitizer_allocator_local_cache.h @@ -140,8 +140,7 @@ struct SizeClassAllocatorLocalCache { PerClass *c = &per_class_[class_id]; TransferBatch *b = allocator->AllocateBatch(&stats_, this, class_id); CHECK_GT(b->Count(), 0); - for (uptr i = 0; i < b->Count(); i++) - c->batch[i] = b->Get(i); + b->CopyToArray(c->batch); c->count = b->Count(); DestroyBatch(class_id, allocator, b); } diff --git a/lib/sanitizer_common/sanitizer_allocator_primary32.h b/lib/sanitizer_common/sanitizer_allocator_primary32.h index 67073402e..58237ca54 100644 --- a/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -49,16 +49,16 @@ class SizeClassAllocator32 { for (uptr i = 0; i < count; i++) batch_[i] = batch[i]; } - void *Get(uptr idx) { - CHECK_LT(idx, count_); - return batch_[idx]; - } uptr Count() const { return count_; } void Clear() { count_ = 0; } void Add(void *ptr) { batch_[count_++] = ptr; CHECK_LE(count_, kMaxNumCached); } + void CopyToArray(void *to_batch[]) { + for (uptr i = 0, n = Count(); i < n; i++) + to_batch[i] = batch_[i]; + } TransferBatch *next; private: diff --git a/lib/sanitizer_common/sanitizer_allocator_primary64.h b/lib/sanitizer_common/sanitizer_allocator_primary64.h index 3552a20fa..37a34e634 100644 --- a/lib/sanitizer_common/sanitizer_allocator_primary64.h +++ b/lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -50,9 +50,9 @@ class SizeClassAllocator64 { for (uptr i = 0; i < count; i++) batch_[i] = batch[i]; } - void *Get(uptr idx) { - CHECK_LT(idx, count_); - return batch_[idx]; + void CopyToArray(void *to_batch[]) { + for (uptr i = 0, n = Count(); i < n; i++) + to_batch[i] = batch_[i]; } uptr Count() const { return count_; } TransferBatch *next; |