Skip to content

Commit aaead93

Browse files
committed
Don't allocate in LocalHeap::new()
One of these is allocated for every task, trying to cut down on allocations cc #11389
1 parent d5e0622 commit aaead93

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/libstd/rt/local_heap.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rt::local::Local;
2323
use rt::task::Task;
2424
use unstable::raw;
2525
use vec::ImmutableVector;
26+
use vec_ng::Vec;
2627

2728
// This has no meaning with out rtdebug also turned on.
2829
#[cfg(rtdebug)]
@@ -33,7 +34,7 @@ static MAGIC: u32 = 0xbadc0ffe;
3334
pub type Box = raw::Box<()>;
3435

3536
pub struct MemoryRegion {
36-
priv allocations: ~[*AllocHeader],
37+
priv allocations: Vec<*AllocHeader>,
3738
priv live_allocations: uint,
3839
}
3940

@@ -48,7 +49,7 @@ impl LocalHeap {
4849
#[inline]
4950
pub fn new() -> LocalHeap {
5051
let region = MemoryRegion {
51-
allocations: ~[],
52+
allocations: Vec::new(),
5253
live_allocations: 0,
5354
};
5455
LocalHeap {
@@ -248,8 +249,8 @@ impl MemoryRegion {
248249
fn release(&mut self, alloc: &AllocHeader) {
249250
alloc.assert_sane();
250251
if TRACK_ALLOCATIONS > 1 {
251-
rtassert!(self.allocations[alloc.index] == alloc as *AllocHeader);
252-
self.allocations[alloc.index] = ptr::null();
252+
rtassert!(self.allocations.as_slice()[alloc.index] == alloc as *AllocHeader);
253+
self.allocations.as_mut_slice()[alloc.index] = ptr::null();
253254
}
254255
}
255256
#[cfg(not(rtdebug))]
@@ -260,8 +261,8 @@ impl MemoryRegion {
260261
fn update(&mut self, alloc: &mut AllocHeader, orig: *AllocHeader) {
261262
alloc.assert_sane();
262263
if TRACK_ALLOCATIONS > 1 {
263-
rtassert!(self.allocations[alloc.index] == orig);
264-
self.allocations[alloc.index] = &*alloc as *AllocHeader;
264+
rtassert!(self.allocations.as_slice()[alloc.index] == orig);
265+
self.allocations.as_mut_slice()[alloc.index] = &*alloc as *AllocHeader;
265266
}
266267
}
267268
#[cfg(not(rtdebug))]
@@ -274,7 +275,7 @@ impl Drop for MemoryRegion {
274275
if self.live_allocations != 0 {
275276
rtabort!("leaked managed memory ({} objects)", self.live_allocations);
276277
}
277-
rtassert!(self.allocations.iter().all(|s| s.is_null()));
278+
rtassert!(self.allocations.as_slice().iter().all(|s| s.is_null()));
278279
}
279280
}
280281

0 commit comments

Comments
 (0)