diff options
| author | bors <bors@rust-lang.org> | 2013-02-14 18:27:54 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-02-14 18:27:54 -0800 |
| commit | 20fd0c53edd2cc5ef5d413b8698b2c5860aa4926 (patch) | |
| tree | 6b3d2071563a7d64e8bd2bb24bc988f480cd8f08 /src/rt | |
| parent | af2f0ef0888d05209bddd16ab210ae0e8400b7de (diff) | |
| parent | 1a41b484bf05514f469e69efd56fcd7039d34db9 (diff) | |
| download | rust-20fd0c53edd2cc5ef5d413b8698b2c5860aa4926.tar.gz rust-20fd0c53edd2cc5ef5d413b8698b2c5860aa4926.zip | |
auto merge of #4938 : thestinger/rust/no_zero, r=brson
I removed the unused wrappers methods named `calloc` because they relied on the malloc wrapper having a `bool zero = true` default parameter (which resulted in some accidental zeroing). Perhaps wrapping the actual calloc function would be useful, but I don't know of an existing use case that could use it so I just removed these. This gives an ~1% performance improvement for TreeMap, which does a lot of small allocations. Vectors use `realloc` which didn't zero before these changes so there's no measurable change in performance.
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/memory_region.cpp | 13 | ||||
| -rw-r--r-- | src/rt/memory_region.h | 3 | ||||
| -rw-r--r-- | src/rt/rust_exchange_alloc.cpp | 10 | ||||
| -rw-r--r-- | src/rt/rust_exchange_alloc.h | 3 | ||||
| -rw-r--r-- | src/rt/rust_kernel.cpp | 5 | ||||
| -rw-r--r-- | src/rt/rust_kernel.h | 1 | ||||
| -rw-r--r-- | src/rt/rust_stack.cpp | 4 | ||||
| -rw-r--r-- | src/rt/rust_task.cpp | 5 |
8 files changed, 8 insertions, 36 deletions
diff --git a/src/rt/memory_region.cpp b/src/rt/memory_region.cpp index 6307730b0f4..6de9d5a1df4 100644 --- a/src/rt/memory_region.cpp +++ b/src/rt/memory_region.cpp @@ -121,8 +121,10 @@ memory_region::realloc(void *mem, size_t orig_size) { } void * -memory_region::malloc(size_t size, const char *tag, bool zero) { +memory_region::malloc(size_t size, const char *tag) { +# if RUSTRT_TRACK_ALLOCATIONS >= 1 size_t old_size = size; +# endif size += HEADER_SIZE; alloc_header *mem = (alloc_header *)::malloc(size); if (mem == NULL) { @@ -143,18 +145,9 @@ memory_region::malloc(size_t size, const char *tag, bool zero) { void *data = get_data(mem); claim_alloc(data); - if(zero) { - memset(data, 0, old_size); - } - return data; } -void * -memory_region::calloc(size_t size, const char *tag) { - return malloc(size, tag, true); -} - memory_region::~memory_region() { if (_synchronized) { _lock.lock(); } if (_live_allocations == 0 && !_detailed_leaks) { diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h index 7a68a0f8af5..999a992eefa 100644 --- a/src/rt/memory_region.h +++ b/src/rt/memory_region.h @@ -77,8 +77,7 @@ private: public: memory_region(rust_env *env, bool synchronized); memory_region(memory_region *parent); - void *malloc(size_t size, const char *tag, bool zero = true); - void *calloc(size_t size, const char *tag); + void *malloc(size_t size, const char *tag); void *realloc(void *mem, size_t size); void free(void *mem); ~memory_region(); diff --git a/src/rt/rust_exchange_alloc.cpp b/src/rt/rust_exchange_alloc.cpp index 6c0204ca736..a92bc4edd41 100644 --- a/src/rt/rust_exchange_alloc.cpp +++ b/src/rt/rust_exchange_alloc.cpp @@ -18,12 +18,9 @@ uintptr_t exchange_count = 0; void * -rust_exchange_alloc::malloc(size_t size, bool zero) { +rust_exchange_alloc::malloc(size_t size) { void *value = ::malloc(size); assert(value); - if (zero) { - memset(value, 0, size); - } sync::increment(exchange_count); @@ -31,11 +28,6 @@ rust_exchange_alloc::malloc(size_t size, bool zero) { } void * -rust_exchange_alloc::calloc(size_t size) { - return this->malloc(size); -} - -void * rust_exchange_alloc::realloc(void *ptr, size_t size) { void *new_ptr = ::realloc(ptr, size); assert(new_ptr); diff --git a/src/rt/rust_exchange_alloc.h b/src/rt/rust_exchange_alloc.h index 1b52929acf1..767caf01323 100644 --- a/src/rt/rust_exchange_alloc.h +++ b/src/rt/rust_exchange_alloc.h @@ -16,8 +16,7 @@ class rust_exchange_alloc { public: - void *malloc(size_t size, bool zero = true); - void *calloc(size_t size); + void *malloc(size_t size); void *realloc(void *mem, size_t size); void free(void *mem); }; diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 6b7a8241416..4d2d6ad344c 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -80,11 +80,6 @@ rust_kernel::malloc(size_t size, const char *tag) { } void * -rust_kernel::calloc(size_t size, const char *tag) { - return exchange_alloc.calloc(size); -} - -void * rust_kernel::realloc(void *mem, size_t size) { return exchange_alloc.realloc(mem, size); } diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 01ebf5ab57b..e65a0bd9289 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -133,7 +133,6 @@ public: void fatal(char const *fmt, ...); void *malloc(size_t size, const char *tag); - void *calloc(size_t size, const char *tag); void *realloc(void *mem, size_t size); void free(void *mem); rust_exchange_alloc *region() { return &exchange_alloc; } diff --git a/src/rt/rust_stack.cpp b/src/rt/rust_stack.cpp index 3bcda8adf40..64ca256ff46 100644 --- a/src/rt/rust_stack.cpp +++ b/src/rt/rust_stack.cpp @@ -58,7 +58,7 @@ check_stack_canary(stk_seg *stk) { stk_seg * create_stack(memory_region *region, size_t sz) { size_t total_sz = sizeof(stk_seg) + sz; - stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack", false); + stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack"); memset(stk, 0, sizeof(stk_seg)); stk->end = (uintptr_t) &stk->data[sz]; add_stack_canary(stk); @@ -75,7 +75,7 @@ destroy_stack(memory_region *region, stk_seg *stk) { stk_seg * create_exchange_stack(rust_exchange_alloc *exchange, size_t sz) { size_t total_sz = sizeof(stk_seg) + sz; - stk_seg *stk = (stk_seg *)exchange->malloc(total_sz, false); + stk_seg *stk = (stk_seg *)exchange->malloc(total_sz); memset(stk, 0, sizeof(stk_seg)); stk->end = (uintptr_t) &stk->data[sz]; add_stack_canary(stk); diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index e51af464e48..63dc1c9833e 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -450,11 +450,6 @@ rust_task::backtrace() { #endif } -void * -rust_task::calloc(size_t size, const char *tag) { - return local_region.calloc(size, tag); -} - size_t rust_task::get_next_stack_size(size_t min, size_t current, size_t requested) { LOG(this, mem, "calculating new stack size for 0x%" PRIxPTR, this); |
