libstd: Added more #[inline] annotations and replaced uses of libc::abort
with the intrinsic.
This commit is contained in:
parent
e063e96ec9
commit
7ca3bea5bf
@ -13,7 +13,6 @@
|
||||
#[macro_escape];
|
||||
|
||||
use std::fmt;
|
||||
use std::libc;
|
||||
|
||||
// Indicates whether we should perform expensive sanity checks, including rtassert!
|
||||
// XXX: Once the runtime matures remove the `true` below to turn off rtassert, etc.
|
||||
@ -124,6 +123,7 @@ pub fn abort(msg: &str) -> ! {
|
||||
abort();
|
||||
|
||||
fn abort() -> ! {
|
||||
unsafe { libc::abort() }
|
||||
use std::unstable::intrinsics;
|
||||
unsafe { intrinsics::abort() }
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
|
||||
|
||||
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
#[inline]
|
||||
pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
|
||||
build(Some(v.len()), |push| {
|
||||
for elem in v.iter() {
|
||||
@ -82,6 +83,7 @@ pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value returned by the function `op`.
|
||||
*/
|
||||
#[inline]
|
||||
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
|
||||
build(Some(n_elts), |push| {
|
||||
let mut i: uint = 0u;
|
||||
@ -95,6 +97,7 @@ pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
|
||||
* Creates an immutable vector of size `n_elts` and initializes the elements
|
||||
* to the value `t`.
|
||||
*/
|
||||
#[inline]
|
||||
pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] {
|
||||
build(Some(n_elts), |push| {
|
||||
let mut i: uint = 0u;
|
||||
@ -109,6 +112,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] {
|
||||
* Creates and initializes an immutable managed vector by moving all the
|
||||
* elements from an owned vector.
|
||||
*/
|
||||
#[inline]
|
||||
pub fn to_managed_move<T>(v: ~[T]) -> @[T] {
|
||||
let mut av = @[];
|
||||
unsafe {
|
||||
@ -124,6 +128,7 @@ pub fn to_managed_move<T>(v: ~[T]) -> @[T] {
|
||||
* Creates and initializes an immutable managed vector by copying all the
|
||||
* elements of a slice.
|
||||
*/
|
||||
#[inline]
|
||||
pub fn to_managed<T:Clone>(v: &[T]) -> @[T] {
|
||||
from_fn(v.len(), |i| v[i].clone())
|
||||
}
|
||||
@ -135,6 +140,7 @@ fn clone(&self) -> @[T] {
|
||||
}
|
||||
|
||||
impl<A> FromIterator<A> for @[A] {
|
||||
#[inline]
|
||||
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> @[A] {
|
||||
let (lower, _) = iterator.size_hint();
|
||||
build(Some(lower), |push| {
|
||||
@ -216,6 +222,7 @@ unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
|
||||
move_val_init(&mut(*p), initval);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
|
||||
reserve_at_least(v, v.len() + 1u);
|
||||
push_fast(v, initval);
|
||||
@ -232,6 +239,7 @@ unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
|
||||
* * v - A vector
|
||||
* * n - The number of elements to reserve space for
|
||||
*/
|
||||
#[inline]
|
||||
pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
|
||||
// Only make the (slow) call into the runtime if we have to
|
||||
if capacity(*v) < n {
|
||||
@ -243,6 +251,7 @@ pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
|
||||
|
||||
// Implementation detail. Shouldn't be public
|
||||
#[allow(missing_doc)]
|
||||
#[inline]
|
||||
pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
|
||||
// check for `uint` overflow
|
||||
unsafe {
|
||||
@ -257,6 +266,7 @@ pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn local_realloc(ptr: *(), size: uint) -> *() {
|
||||
use rt::local::Local;
|
||||
use rt::task::Task;
|
||||
@ -281,6 +291,7 @@ fn local_realloc(ptr: *(), size: uint) -> *() {
|
||||
* * v - A vector
|
||||
* * n - The number of elements to reserve space for
|
||||
*/
|
||||
#[inline]
|
||||
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
|
||||
reserve(v, uint::next_power_of_two(n));
|
||||
}
|
||||
|
@ -159,7 +159,7 @@
|
||||
pub use libc::funcs::c95::stdio::{fwrite, perror, puts, remove, rewind};
|
||||
pub use libc::funcs::c95::stdio::{setbuf, setvbuf, tmpfile, ungetc};
|
||||
|
||||
pub use libc::funcs::c95::stdlib::{abort, abs, atof, atoi, calloc, exit};
|
||||
pub use libc::funcs::c95::stdlib::{abs, atof, atoi, calloc, exit};
|
||||
pub use libc::funcs::c95::stdlib::{free, getenv, labs, malloc, rand};
|
||||
pub use libc::funcs::c95::stdlib::{realloc, srand, strtod, strtol};
|
||||
pub use libc::funcs::c95::stdlib::{strtoul, system};
|
||||
@ -3226,7 +3226,6 @@ pub fn strtoul(s: *c_char, endp: **c_char, base: c_int)
|
||||
pub fn malloc(size: size_t) -> *c_void;
|
||||
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
|
||||
pub fn free(p: *c_void);
|
||||
pub fn abort() -> !;
|
||||
pub fn exit(status: c_int) -> !;
|
||||
// Omitted: atexit.
|
||||
pub fn system(s: *c_char) -> c_int;
|
||||
|
@ -280,7 +280,8 @@ fn get_with<T:'static,
|
||||
}
|
||||
|
||||
fn abort() -> ! {
|
||||
unsafe { libc::abort() }
|
||||
use std::unstable::intrinsics;
|
||||
unsafe { intrinsics::abort() }
|
||||
}
|
||||
|
||||
/// Inserts a value into task local storage. If the key is already present in
|
||||
|
@ -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::<raw::Box<()>>();
|
||||
@ -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);
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ pub struct LocalHeap {
|
||||
}
|
||||
|
||||
impl LocalHeap {
|
||||
#[inline]
|
||||
pub fn new() -> LocalHeap {
|
||||
let region = MemoryRegion {
|
||||
allocations: ~[],
|
||||
@ -60,6 +61,7 @@ pub fn new() -> 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 @@ pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box {
|
||||
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::<Box>();
|
||||
@ -100,6 +103,7 @@ pub fn realloc(&mut self, ptr: *mut Box, size: uint) -> *mut Box {
|
||||
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 @@ fn from(a_box: *mut Box) -> *mut 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 @@ fn malloc(&mut self, size: uint) -> *mut Box {
|
||||
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 @@ fn realloc(&mut self, alloc: *mut Box, size: uint) -> *mut Box {
|
||||
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 @@ fn claim(&mut self, alloc: &mut AllocHeader) {
|
||||
}
|
||||
}
|
||||
#[cfg(not(rtdebug))]
|
||||
#[inline]
|
||||
fn claim(&mut self, _alloc: &mut AllocHeader) {}
|
||||
|
||||
#[cfg(rtdebug)]
|
||||
@ -260,6 +268,7 @@ fn release(&mut self, alloc: &AllocHeader) {
|
||||
}
|
||||
}
|
||||
#[cfg(not(rtdebug))]
|
||||
#[inline]
|
||||
fn release(&mut self, _alloc: &AllocHeader) {}
|
||||
|
||||
#[cfg(rtdebug)]
|
||||
@ -271,6 +280,7 @@ fn update(&mut self, alloc: &mut AllocHeader, orig: *AllocHeader) {
|
||||
}
|
||||
}
|
||||
#[cfg(not(rtdebug))]
|
||||
#[inline]
|
||||
fn update(&mut self, _alloc: &mut AllocHeader, _orig: *AllocHeader) {}
|
||||
}
|
||||
|
||||
@ -283,6 +293,7 @@ fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
@ -141,6 +141,7 @@ pub fn abort(msg: &str) -> ! {
|
||||
abort();
|
||||
|
||||
fn abort() -> ! {
|
||||
unsafe { libc::abort() }
|
||||
use std::unstable::intrinsics;
|
||||
unsafe { intrinsics::abort() }
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t
|
||||
}
|
||||
|
||||
#[lang="malloc"]
|
||||
#[inline]
|
||||
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
::rt::local_heap::local_malloc(td, size)
|
||||
}
|
||||
@ -37,6 +38,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
||||
// inside a landing pad may corrupt the state of the exception handler. If a
|
||||
// problem occurs, call exit instead.
|
||||
#[lang="free"]
|
||||
#[inline]
|
||||
pub unsafe fn local_free(ptr: *c_char) {
|
||||
::rt::local_heap::local_free(ptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user