Skip to content

Commit 093e6b7

Browse files
committed
---
yaml --- r: 12014 b: refs/heads/master c: ba39e27 h: refs/heads/master v: v3
1 parent 4a02e7b commit 093e6b7

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 575692c3bcb20897cf07fcd21769c8a7dbdd948e
2+
refs/heads/master: ba39e277e2c63909cb35a0dd68e9f3bab728c425
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libstd/arena.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Dynamic arenas.
2+
3+
export arena, arena_with_size;
4+
5+
import list;
6+
7+
type chunk = {data: [u8], mut fill: uint};
8+
type arena = {mut chunks: list::list<@chunk>};
9+
10+
fn chunk(size: uint) -> @chunk {
11+
@{ data: vec::from_elem(size, 0u8), mut fill: 0u }
12+
}
13+
14+
fn arena_with_size(initial_size: uint) -> arena {
15+
ret {mut chunks: list::cons(chunk(initial_size), @list::nil)};
16+
}
17+
18+
fn arena() -> arena {
19+
arena_with_size(32u)
20+
}
21+
22+
impl arena for arena {
23+
unsafe fn alloc<T>(n_bytes: uint) -> &self.T {
24+
let mut head = list::head(self.chunks);
25+
if head.fill + n_bytes > vec::len(head.data) {
26+
// Allocate a new chunk.
27+
let new_min_chunk_size = uint::max(n_bytes, vec::len(head.data));
28+
head = chunk(uint::next_power_of_two(new_min_chunk_size));
29+
self.chunks = list::cons(head, @self.chunks);
30+
}
31+
32+
let start = vec::unsafe::to_ptr(head.data);
33+
let p = ptr::offset(start, head.fill);
34+
head.fill += n_bytes;
35+
ret unsafe::reinterpret_cast(p);
36+
}
37+
}
38+

trunk/src/libstd/std.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
export net, uv;
1212
export c_vec, four, tri, util;
1313
export bitv, deque, fun_treemap, list, map, smallintmap, sort, treemap, ufind;
14-
export rope;
14+
export rope, arena;
1515
export ebml, dbg, getopts, json, rand, sha1, term, time, prettyprint;
1616
export test, tempfile, serialization;
1717

@@ -56,6 +56,7 @@ mod tempfile;
5656
mod term;
5757
mod time;
5858
mod prettyprint;
59+
mod arena;
5960

6061
#[cfg(unicode)]
6162
mod unicode;

trunk/src/rustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,9 @@ fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer,
672672
*pt, none, tps, ctor.node.dec)
673673
}
674674
_ {}
675+
}
676+
}
675677
}
676-
}
677-
}
678678
},
679679
visit_native_item: {|ni, cx, v|
680680
visit::visit_native_item(ni, cx, v);

0 commit comments

Comments
 (0)