Skip to content

Commit 7bebdbd

Browse files
committed
auto merge of #11561 : eddyb/rust/moar-inlines, r=pcwalton
2 parents 180ac0c + 7ca3bea commit 7bebdbd

File tree

8 files changed

+36
-11
lines changed

8 files changed

+36
-11
lines changed

src/libgreen/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#[macro_escape];
1414

1515
use std::fmt;
16-
use std::libc;
1716

1817
// Indicates whether we should perform expensive sanity checks, including rtassert!
1918
// XXX: Once the runtime matures remove the `true` below to turn off rtassert, etc.
@@ -124,6 +123,7 @@ memory and partly incapable of presentation to others.",
124123
abort();
125124

126125
fn abort() -> ! {
127-
unsafe { libc::abort() }
126+
use std::unstable::intrinsics;
127+
unsafe { intrinsics::abort() }
128128
}
129129
}

src/libstd/at_vec.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] {
6868

6969

7070
/// Apply a function to each element of a vector and return the results
71+
#[inline]
7172
pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
7273
build(Some(v.len()), |push| {
7374
for elem in v.iter() {
@@ -82,6 +83,7 @@ pub fn map<T, U>(v: &[T], f: |x: &T| -> U) -> @[U] {
8283
* Creates an immutable vector of size `n_elts` and initializes the elements
8384
* to the value returned by the function `op`.
8485
*/
86+
#[inline]
8587
pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
8688
build(Some(n_elts), |push| {
8789
let mut i: uint = 0u;
@@ -95,6 +97,7 @@ pub fn from_fn<T>(n_elts: uint, op: |uint| -> T) -> @[T] {
9597
* Creates an immutable vector of size `n_elts` and initializes the elements
9698
* to the value `t`.
9799
*/
100+
#[inline]
98101
pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] {
99102
build(Some(n_elts), |push| {
100103
let mut i: uint = 0u;
@@ -109,6 +112,7 @@ pub fn from_elem<T:Clone>(n_elts: uint, t: T) -> @[T] {
109112
* Creates and initializes an immutable managed vector by moving all the
110113
* elements from an owned vector.
111114
*/
115+
#[inline]
112116
pub fn to_managed_move<T>(v: ~[T]) -> @[T] {
113117
let mut av = @[];
114118
unsafe {
@@ -124,6 +128,7 @@ pub fn to_managed_move<T>(v: ~[T]) -> @[T] {
124128
* Creates and initializes an immutable managed vector by copying all the
125129
* elements of a slice.
126130
*/
131+
#[inline]
127132
pub fn to_managed<T:Clone>(v: &[T]) -> @[T] {
128133
from_fn(v.len(), |i| v[i].clone())
129134
}
@@ -135,6 +140,7 @@ impl<T> Clone for @[T] {
135140
}
136141

137142
impl<A> FromIterator<A> for @[A] {
143+
#[inline]
138144
fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> @[A] {
139145
let (lower, _) = iterator.size_hint();
140146
build(Some(lower), |push| {
@@ -216,6 +222,7 @@ pub mod raw {
216222
move_val_init(&mut(*p), initval);
217223
}
218224

225+
#[inline]
219226
unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
220227
reserve_at_least(v, v.len() + 1u);
221228
push_fast(v, initval);
@@ -232,6 +239,7 @@ pub mod raw {
232239
* * v - A vector
233240
* * n - The number of elements to reserve space for
234241
*/
242+
#[inline]
235243
pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
236244
// Only make the (slow) call into the runtime if we have to
237245
if capacity(*v) < n {
@@ -243,6 +251,7 @@ pub mod raw {
243251

244252
// Implementation detail. Shouldn't be public
245253
#[allow(missing_doc)]
254+
#[inline]
246255
pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
247256
// check for `uint` overflow
248257
unsafe {
@@ -257,6 +266,7 @@ pub mod raw {
257266
}
258267
}
259268

269+
#[inline]
260270
fn local_realloc(ptr: *(), size: uint) -> *() {
261271
use rt::local::Local;
262272
use rt::task::Task;
@@ -281,6 +291,7 @@ pub mod raw {
281291
* * v - A vector
282292
* * n - The number of elements to reserve space for
283293
*/
294+
#[inline]
284295
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
285296
reserve(v, uint::next_power_of_two(n));
286297
}

src/libstd/libc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub use libc::funcs::c95::stdio::{fread, freopen, fseek, fsetpos, ftell};
159159
pub use libc::funcs::c95::stdio::{fwrite, perror, puts, remove, rewind};
160160
pub use libc::funcs::c95::stdio::{setbuf, setvbuf, tmpfile, ungetc};
161161

162-
pub use libc::funcs::c95::stdlib::{abort, abs, atof, atoi, calloc, exit};
162+
pub use libc::funcs::c95::stdlib::{abs, atof, atoi, calloc, exit};
163163
pub use libc::funcs::c95::stdlib::{free, getenv, labs, malloc, rand};
164164
pub use libc::funcs::c95::stdlib::{realloc, srand, strtod, strtol};
165165
pub use libc::funcs::c95::stdlib::{strtoul, system};
@@ -3226,7 +3226,6 @@ pub mod funcs {
32263226
pub fn malloc(size: size_t) -> *c_void;
32273227
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
32283228
pub fn free(p: *c_void);
3229-
pub fn abort() -> !;
32303229
pub fn exit(status: c_int) -> !;
32313230
// Omitted: atexit.
32323231
pub fn system(s: *c_char) -> c_int;

src/libstd/local_data.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ fn get_with<T:'static,
280280
}
281281

282282
fn abort() -> ! {
283-
unsafe { libc::abort() }
283+
use std::unstable::intrinsics;
284+
unsafe { intrinsics::abort() }
284285
}
285286

286287
/// Inserts a value into task local storage. If the key is already present in

src/libstd/rt/global_heap.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010

1111
use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc};
1212
use ptr::RawPtr;
13-
use unstable::intrinsics::TyDesc;
13+
use unstable::intrinsics::{TyDesc, abort};
1414
use unstable::raw;
1515
use mem::size_of;
1616

17-
extern {
18-
fn abort();
19-
}
20-
2117
#[inline]
2218
pub fn get_box_size(body_size: uint, body_align: uint) -> uint {
2319
let header_size = size_of::<raw::Box<()>>();
@@ -34,6 +30,7 @@ fn align_to(size: uint, align: uint) -> uint {
3430
}
3531

3632
/// A wrapper around libc::malloc, aborting on out-of-memory
33+
#[inline]
3734
pub unsafe fn malloc_raw(size: uint) -> *c_void {
3835
let p = malloc(size as size_t);
3936
if p.is_null() {
@@ -44,6 +41,7 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
4441
}
4542

4643
/// A wrapper around libc::realloc, aborting on out-of-memory
44+
#[inline]
4745
pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void {
4846
let p = realloc(ptr, size as size_t);
4947
if p.is_null() {
@@ -94,6 +92,7 @@ pub unsafe fn exchange_free_(ptr: *c_char) {
9492
exchange_free(ptr)
9593
}
9694

95+
#[inline]
9796
pub unsafe fn exchange_free(ptr: *c_char) {
9897
free(ptr as *c_void);
9998
}

src/libstd/rt/local_heap.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct LocalHeap {
4848
}
4949

5050
impl LocalHeap {
51+
#[inline]
5152
pub fn new() -> LocalHeap {
5253
let region = MemoryRegion {
5354
allocations: ~[],
@@ -60,6 +61,7 @@ impl LocalHeap {
6061
}
6162
}
6263

64+
#[inline]
6365
pub fn alloc(&mut self, td: *TyDesc, size: uint) -> *mut Box {
6466
let total_size = global_heap::get_box_size(size, unsafe { (*td).align });
6567
let alloc = self.memory_region.malloc(total_size);
@@ -80,6 +82,7 @@ impl LocalHeap {
8082
return alloc;
8183
}
8284

85+
#[inline]
8386
pub fn realloc(&mut self, ptr: *mut Box, size: uint) -> *mut Box {
8487
// Make sure that we can't use `mybox` outside of this scope
8588
let total_size = size + mem::size_of::<Box>();
@@ -100,6 +103,7 @@ impl LocalHeap {
100103
return new_box;
101104
}
102105

106+
#[inline]
103107
pub fn free(&mut self, alloc: *mut Box) {
104108
{
105109
// Make sure that we can't use `mybox` outside of this scope
@@ -196,6 +200,7 @@ impl AllocHeader {
196200
}
197201

198202
impl MemoryRegion {
203+
#[inline]
199204
fn malloc(&mut self, size: uint) -> *mut Box {
200205
let total_size = size + AllocHeader::size();
201206
let alloc: *AllocHeader = unsafe {
@@ -210,6 +215,7 @@ impl MemoryRegion {
210215
return alloc.as_box();
211216
}
212217

218+
#[inline]
213219
fn realloc(&mut self, alloc: *mut Box, size: uint) -> *mut Box {
214220
rtassert!(!alloc.is_null());
215221
let orig_alloc = AllocHeader::from(alloc);
@@ -228,6 +234,7 @@ impl MemoryRegion {
228234
return alloc.as_box();
229235
}
230236

237+
#[inline]
231238
fn free(&mut self, alloc: *mut Box) {
232239
rtassert!(!alloc.is_null());
233240
let alloc = AllocHeader::from(alloc);
@@ -249,6 +256,7 @@ impl MemoryRegion {
249256
}
250257
}
251258
#[cfg(not(rtdebug))]
259+
#[inline]
252260
fn claim(&mut self, _alloc: &mut AllocHeader) {}
253261

254262
#[cfg(rtdebug)]
@@ -260,6 +268,7 @@ impl MemoryRegion {
260268
}
261269
}
262270
#[cfg(not(rtdebug))]
271+
#[inline]
263272
fn release(&mut self, _alloc: &AllocHeader) {}
264273

265274
#[cfg(rtdebug)]
@@ -271,6 +280,7 @@ impl MemoryRegion {
271280
}
272281
}
273282
#[cfg(not(rtdebug))]
283+
#[inline]
274284
fn update(&mut self, _alloc: &mut AllocHeader, _orig: *AllocHeader) {}
275285
}
276286

@@ -283,6 +293,7 @@ impl Drop for MemoryRegion {
283293
}
284294
}
285295

296+
#[inline]
286297
pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char {
287298
// XXX: Unsafe borrow for speed. Lame.
288299
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
295306
}
296307

297308
// A little compatibility function
309+
#[inline]
298310
pub unsafe fn local_free(ptr: *libc::c_char) {
299311
// XXX: Unsafe borrow for speed. Lame.
300312
let task_ptr: Option<*mut Task> = Local::try_unsafe_borrow();

src/libstd/rt/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ memory and partly incapable of presentation to others.",
141141
abort();
142142

143143
fn abort() -> ! {
144-
unsafe { libc::abort() }
144+
use std::unstable::intrinsics;
145+
unsafe { intrinsics::abort() }
145146
}
146147
}

src/libstd/unstable/lang.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn fail_bounds_check(file: *c_char, line: size_t, index: size_t, len: size_t
2929
}
3030

3131
#[lang="malloc"]
32+
#[inline]
3233
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
3334
::rt::local_heap::local_malloc(td, size)
3435
}
@@ -37,6 +38,7 @@ pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
3738
// inside a landing pad may corrupt the state of the exception handler. If a
3839
// problem occurs, call exit instead.
3940
#[lang="free"]
41+
#[inline]
4042
pub unsafe fn local_free(ptr: *c_char) {
4143
::rt::local_heap::local_free(ptr);
4244
}

0 commit comments

Comments
 (0)