[compiler-rt] r277563 - [sanitizer] remove one redundant loop from the allocator

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 20:42:55 PDT 2016


Author: kcc
Date: Tue Aug  2 22:42:55 2016
New Revision: 277563

URL: http://llvm.org/viewvc/llvm-project?rev=277563&view=rev
Log:
[sanitizer] remove one redundant loop from the allocator

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_local_cache.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_local_cache.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_local_cache.h?rev=277563&r1=277562&r2=277563&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_local_cache.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_local_cache.h Tue Aug  2 22:42:55 2016
@@ -119,12 +119,11 @@ struct SizeClassAllocatorLocalCache {
   NOINLINE void Drain(SizeClassAllocator *allocator, uptr class_id) {
     InitCache();
     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);
-    b->SetFromArray(c->batch, cnt);
-    for (uptr i = 0; i < cnt; i++)
-      c->batch[i] = c->batch[i + c->max_count / 2];
-
+    uptr first_idx_to_drain = c->count - cnt;
+    Batch *b =
+        CreateBatch(class_id, allocator, (Batch *)c->batch[first_idx_to_drain]);
+    b->SetFromArray(&c->batch[first_idx_to_drain], cnt);
     c->count -= cnt;
     allocator->DeallocateBatch(&stats_, class_id, b);
   }




More information about the llvm-commits mailing list