From 7ca3bea5bfd15dd960e6346eebf72422b0020d6b Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 15 Jan 2014 11:45:12 +0200 Subject: libstd: Added more #[inline] annotations and replaced uses of `libc::abort` with the intrinsic. --- src/libstd/rt/global_heap.rs | 9 ++++----- src/libstd/rt/local_heap.rs | 12 ++++++++++++ src/libstd/rt/util.rs | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 7a417990a4c..ce4072fb1ab 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -10,14 +10,10 @@ use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc}; use ptr::RawPtr; -use unstable::intrinsics::TyDesc; +use unstable::intrinsics::{TyDesc, abort}; use unstable::raw; use mem::size_of; -extern { - fn abort(); -} - #[inline] pub fn get_box_size(body_size: uint, body_align: uint) -> uint { let header_size = size_of::>(); @@ -34,6 +30,7 @@ fn align_to(size: uint, align: uint) -> uint { } /// A wrapper around libc::malloc, aborting on out-of-memory +#[inline] pub unsafe fn malloc_raw(size: uint) -> *c_void { let p = malloc(size as size_t); if p.is_null() { @@ -44,6 +41,7 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void { } /// A wrapper around libc::realloc, aborting on out-of-memory +#[inline] pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void { let p = realloc(ptr, size as size_t); if p.is_null() { @@ -94,6 +92,7 @@ pub unsafe fn exchange_free_(ptr: *c_char) { exchange_free(ptr) } +#[inline] pub unsafe fn exchange_free(ptr: *c_char) { free(ptr as *c_void); } diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 1be942b2db1..90179612272 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -48,6 +48,7 @@ pub struct LocalHeap { } impl LocalHeap { + #[inline] pub fn new() -> LocalHeap { let region = MemoryRegion { allocations: ~[], @@ -60,6 +61,7 @@ impl LocalHeap { } } + #[inline] pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box { let total_size = global_heap::get_box_size(size, unsafe { (*td).align }); let alloc = self.memory_region.malloc(total_size); @@ -80,6 +82,7 @@ impl LocalHeap { return alloc; } + #[inline] pub fn realloc(&mut self, ptr: *mut Box, size: uint) -> *mut Box { // Make sure that we can't use `mybox` outside of this scope let total_size = size + mem::size_of::(); @@ -100,6 +103,7 @@ impl LocalHeap { return new_box; } + #[inline] pub fn free(&mut self, alloc: *mut Box) { { // Make sure that we can't use `mybox` outside of this scope @@ -196,6 +200,7 @@ impl AllocHeader { } impl MemoryRegion { + #[inline] fn malloc(&mut self, size: uint) -> *mut Box { let total_size = size + AllocHeader::size(); let alloc: *AllocHeader = unsafe { @@ -210,6 +215,7 @@ impl MemoryRegion { return alloc.as_box(); } + #[inline] fn realloc(&mut self, alloc: *mut Box, size: uint) -> *mut Box { rtassert!(!alloc.is_null()); let orig_alloc = AllocHeader::from(alloc); @@ -228,6 +234,7 @@ impl MemoryRegion { return alloc.as_box(); } + #[inline] fn free(&mut self, alloc: *mut Box) { rtassert!(!alloc.is_null()); let alloc = AllocHeader::from(alloc); @@ -249,6 +256,7 @@ impl MemoryRegion { } } #[cfg(not(rtdebug))] + #[inline] fn claim(&mut self, _alloc: &mut AllocHeader) {} #[cfg(rtdebug)] @@ -260,6 +268,7 @@ impl MemoryRegion { } } #[cfg(not(rtdebug))] + #[inline] fn release(&mut self, _alloc: &AllocHeader) {} #[cfg(rtdebug)] @@ -271,6 +280,7 @@ impl MemoryRegion { } } #[cfg(not(rtdebug))] + #[inline] fn update(&mut self, _alloc: &mut AllocHeader, _orig: *AllocHeader) {} } @@ -283,6 +293,7 @@ impl Drop for MemoryRegion { } } +#[inline] pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char { // XXX: Unsafe borrow for speed. Lame. let task: Option<*mut Task> = Local::try_unsafe_borrow(); @@ -295,6 +306,7 @@ pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c } // A little compatibility function +#[inline] pub unsafe fn local_free(ptr: *libc::c_char) { // XXX: Unsafe borrow for speed. Lame. let task_ptr: Option<*mut Task> = Local::try_unsafe_borrow(); diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index ee336d7d847..a5d5a4677f1 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -141,6 +141,7 @@ memory and partly incapable of presentation to others.", abort(); fn abort() -> ! { - unsafe { libc::abort() } + use std::unstable::intrinsics; + unsafe { intrinsics::abort() } } } -- cgit 1.4.1-3-g733a5