summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator_local_cache.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-08-03 00:14:10 +0000
committerKostya Serebryany <kcc@google.com>2016-08-03 00:14:10 +0000
commit89a13f837f8bf0941e092ca757f65f65230110aa (patch)
tree5af28408fcdb5adfb5cfff154fb0ec97c447554d /lib/sanitizer_common/sanitizer_allocator_local_cache.h
parentb3e6005f5bc27428ce7c4f5a58db2bb962039dd9 (diff)
[sanitizer] refactor TransferBatch to hide the implementation. NFC expected. Second attempt after failed r276383 which was reverted.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator_local_cache.h')
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_local_cache.h16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_local_cache.h b/lib/sanitizer_common/sanitizer_allocator_local_cache.h
index 5c42707c6..780c45c0c 100644
--- a/lib/sanitizer_common/sanitizer_allocator_local_cache.h
+++ b/lib/sanitizer_common/sanitizer_allocator_local_cache.h
@@ -109,10 +109,10 @@ struct SizeClassAllocatorLocalCache {
InitCache();
PerClass *c = &per_class_[class_id];
Batch *b = allocator->AllocateBatch(&stats_, this, class_id);
- CHECK_GT(b->count, 0);
- for (uptr i = 0; i < b->count; i++)
- c->batch[i] = b->batch[i];
- c->count = b->count;
+ CHECK_GT(b->Count(), 0);
+ for (uptr i = 0; i < b->Count(); i++)
+ c->batch[i] = b->Get(i);
+ c->count = b->Count();
DestroyBatch(class_id, allocator, b);
}
@@ -121,13 +121,11 @@ struct SizeClassAllocatorLocalCache {
PerClass *c = &per_class_[class_id];
Batch *b = CreateBatch(class_id, allocator, (Batch*)c->batch[0]);
uptr cnt = Min(c->max_count / 2, c->count);
- for (uptr i = 0; i < cnt; i++) {
- b->batch[i] = c->batch[i];
+ b->SetFromArray(c->batch, cnt);
+ for (uptr i = 0; i < cnt; i++)
c->batch[i] = c->batch[i + c->max_count / 2];
- }
- b->count = cnt;
+
c->count -= cnt;
- CHECK_GT(b->count, 0);
allocator->DeallocateBatch(&stats_, class_id, b);
}
};