Skip to content

Commit c0f8288

Browse files
committed
---
yaml --- r: 3920 b: refs/heads/master c: 1a6419b h: refs/heads/master v: v3
1 parent 52ebcbc commit c0f8288

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b3dee955144a722da50e17dde62cb36cbcccf73f
2+
refs/heads/master: 1a6419bd731adeaa8779b490716449f9a369e2fa

trunk/src/comp/metadata/encoder.rs

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import std::ivec;
44
import std::str;
5-
import std::vec;
65
import std::uint;
76
import std::ioivec;
87
import std::option;
@@ -39,8 +38,8 @@ fn encode_def_id(&ebmlivec::writer ebml_w, &def_id id) {
3938
}
4039

4140
fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
42-
&vec[str] path,
43-
&mutable vec[tup(str, uint)] index) {
41+
&str[] path,
42+
&mutable (tup(str, uint))[] index) {
4443
for (variant variant in variants) {
4544
add_to_index(ebml_w, path, index, variant.node.name);
4645
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
@@ -50,15 +49,15 @@ fn encode_tag_variant_paths(&ebmlivec::writer ebml_w, &variant[] variants,
5049
}
5150
}
5251

53-
fn add_to_index(&ebmlivec::writer ebml_w, &vec[str] path,
54-
&mutable vec[tup(str, uint)] index, &str name) {
55-
auto full_path = path + [name];
56-
index += [tup(str::connect(full_path, "::"), ebml_w.writer.tell())];
52+
fn add_to_index(&ebmlivec::writer ebml_w, &str[] path,
53+
&mutable (tup(str, uint))[] index, &str name) {
54+
auto full_path = path + ~[name];
55+
index += ~[tup(str::connect_ivec(full_path, "::"), ebml_w.writer.tell())];
5756
}
5857

5958
fn encode_native_module_item_paths(&ebmlivec::writer ebml_w,
60-
&native_mod nmod, &vec[str] path,
61-
&mutable vec[tup(str, uint)] index) {
59+
&native_mod nmod, &str[] path,
60+
&mutable (tup(str, uint))[] index) {
6261
for (@native_item nitem in nmod.items) {
6362
add_to_index(ebml_w, path, index, nitem.ident);
6463
ebmlivec::start_tag(ebml_w, tag_paths_data_item);
@@ -69,8 +68,8 @@ fn encode_native_module_item_paths(&ebmlivec::writer ebml_w,
6968
}
7069

7170
fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
72-
&vec[str] path,
73-
&mutable vec[tup(str, uint)] index) {
71+
&str[] path,
72+
&mutable (tup(str, uint))[] index) {
7473
for (@item it in module.items) {
7574
if (!is_exported(it.ident, module)) { cont; }
7675
alt (it.node) {
@@ -93,7 +92,7 @@ fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
9392
ebmlivec::start_tag(ebml_w, tag_paths_data_mod);
9493
encode_name(ebml_w, it.ident);
9594
encode_def_id(ebml_w, local_def(it.id));
96-
encode_module_item_paths(ebml_w, _mod, path + [it.ident],
95+
encode_module_item_paths(ebml_w, _mod, path + ~[it.ident],
9796
index);
9897
ebmlivec::end_tag(ebml_w);
9998
}
@@ -103,7 +102,7 @@ fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
103102
encode_name(ebml_w, it.ident);
104103
encode_def_id(ebml_w, local_def(it.id));
105104
encode_native_module_item_paths(ebml_w, nmod,
106-
path + [it.ident], index);
105+
path + ~[it.ident], index);
107106
ebmlivec::end_tag(ebml_w);
108107
}
109108
case (item_ty(_, ?tps)) {
@@ -149,10 +148,10 @@ fn encode_module_item_paths(&ebmlivec::writer ebml_w, &_mod module,
149148
}
150149
}
151150

152-
fn encode_item_paths(&ebmlivec::writer ebml_w, &@crate crate) ->
153-
vec[tup(str, uint)] {
154-
let vec[tup(str, uint)] index = [];
155-
let vec[str] path = [];
151+
fn encode_item_paths(&ebmlivec::writer ebml_w, &@crate crate)
152+
-> (tup(str, uint))[] {
153+
let (tup(str, uint))[] index = ~[];
154+
let str[] path = ~[];
156155
ebmlivec::start_tag(ebml_w, tag_paths);
157156
encode_module_item_paths(ebml_w, crate.node.module, path, index);
158157
ebmlivec::end_tag(ebml_w);
@@ -213,10 +212,10 @@ fn encode_tag_id(&ebmlivec::writer ebml_w, &def_id id) {
213212

214213
fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
215214
node_id id, &variant[] variants,
216-
&mutable vec[tup(int, uint)] index,
215+
&mutable (tup(int, uint))[] index,
217216
&ty_param[] ty_params) {
218217
for (variant variant in variants) {
219-
index += [tup(variant.node.id, ebml_w.writer.tell())];
218+
index += ~[tup(variant.node.id, ebml_w.writer.tell())];
220219
ebmlivec::start_tag(ebml_w, tag_items_data_item);
221220
encode_def_id(ebml_w, local_def(variant.node.id));
222221
encode_kind(ebml_w, 'v' as u8);
@@ -233,7 +232,7 @@ fn encode_tag_variant_info(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
233232
}
234233

235234
fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
236-
@item item, &mutable vec[tup(int, uint)] index) {
235+
@item item, &mutable (tup(int, uint))[] index) {
237236
alt (item.node) {
238237
case (item_const(_, _)) {
239238
ebmlivec::start_tag(ebml_w, tag_items_data_item);
@@ -302,7 +301,7 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
302301
encode_symbol(ecx, ebml_w, item.id);
303302
ebmlivec::end_tag(ebml_w);
304303

305-
index += [tup(ctor_id, ebml_w.writer.tell())];
304+
index += ~[tup(ctor_id, ebml_w.writer.tell())];
306305
ebmlivec::start_tag(ebml_w, tag_items_data_item);
307306
encode_def_id(ebml_w, local_def(ctor_id));
308307
encode_kind(ebml_w, 'f' as u8);
@@ -321,7 +320,7 @@ fn encode_info_for_item(@encode_ctxt ecx, &ebmlivec::writer ebml_w,
321320
encode_type(ecx, ebml_w, ty::ty_fn_ret(ecx.ccx.tcx, fn_ty));
322321
ebmlivec::end_tag(ebml_w);
323322

324-
index += [tup(ctor_id, ebml_w.writer.tell())];
323+
index += ~[tup(ctor_id, ebml_w.writer.tell())];
325324
ebmlivec::start_tag(ebml_w, tag_items_data_item);
326325
encode_def_id(ebml_w, local_def(ctor_id));
327326
encode_kind(ebml_w, 'f' as u8);
@@ -355,19 +354,19 @@ fn encode_info_for_native_item(&@encode_ctxt ecx, &ebmlivec::writer ebml_w,
355354
ebmlivec::end_tag(ebml_w);
356355
}
357356

358-
fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w) ->
359-
vec[tup(int, uint)] {
360-
let vec[tup(int, uint)] index = [];
357+
fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w)
358+
-> (tup(int, uint))[] {
359+
let (tup(int, uint))[] index = ~[];
361360
ebmlivec::start_tag(ebml_w, tag_items_data);
362361
for each (@tup(node_id, middle::ast_map::ast_node) kvp in
363362
ecx.ccx.ast_map.items()) {
364363
alt (kvp._1) {
365364
case (middle::ast_map::node_item(?i)) {
366-
index += [tup(kvp._0, ebml_w.writer.tell())];
365+
index += ~[tup(kvp._0, ebml_w.writer.tell())];
367366
encode_info_for_item(ecx, ebml_w, i, index);
368367
}
369368
case (middle::ast_map::node_native_item(?i)) {
370-
index += [tup(kvp._0, ebml_w.writer.tell())];
369+
index += ~[tup(kvp._0, ebml_w.writer.tell())];
371370
encode_info_for_native_item(ecx, ebml_w, i);
372371
}
373372
case (_) {}
@@ -380,27 +379,32 @@ fn encode_info_for_items(&@encode_ctxt ecx, &ebmlivec::writer ebml_w) ->
380379

381380
// Path and definition ID indexing
382381

383-
fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) ->
384-
vec[vec[tup(T, uint)]] {
385-
let vec[mutable vec[tup(T, uint)]] buckets = vec::empty_mut();
386-
for each (uint i in uint::range(0u, 256u)) { buckets += [mutable []]; }
382+
fn create_index[T](&(tup(T, uint))[] index, fn(&T) -> uint hash_fn)
383+
-> (@(tup(T, uint))[])[] {
384+
let (@mutable (tup(T,uint))[])[] buckets = ~[];
385+
for each (uint i in uint::range(0u, 256u)) { buckets += ~[@mutable ~[]]; }
387386
for (tup(T, uint) elt in index) {
388387
auto h = hash_fn(elt._0);
389-
buckets.(h % 256u) += [elt];
388+
*(buckets.(h % 256u)) += ~[elt];
390389
}
391-
ret vec::freeze(buckets);
390+
391+
auto buckets_frozen = ~[];
392+
for (@mutable (tup(T, uint))[] bucket in buckets) {
393+
buckets_frozen += ~[@*bucket];
394+
}
395+
ret buckets_frozen;
392396
}
393397

394-
fn encode_index[T](&ebmlivec::writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
398+
fn encode_index[T](&ebmlivec::writer ebml_w, &(@(tup(T, uint))[])[] buckets,
395399
fn(&ioivec::writer, &T) write_fn) {
396400
auto writer = ioivec::new_writer_(ebml_w.writer);
397401
ebmlivec::start_tag(ebml_w, tag_index);
398-
let vec[uint] bucket_locs = [];
402+
let uint[] bucket_locs = ~[];
399403
ebmlivec::start_tag(ebml_w, tag_index_buckets);
400-
for (vec[tup(T, uint)] bucket in buckets) {
401-
bucket_locs += [ebml_w.writer.tell()];
404+
for (@(tup(T, uint))[] bucket in buckets) {
405+
bucket_locs += ~[ebml_w.writer.tell()];
402406
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket);
403-
for (tup(T, uint) elt in bucket) {
407+
for (tup(T, uint) elt in *bucket) {
404408
ebmlivec::start_tag(ebml_w, tag_index_buckets_bucket_elt);
405409
writer.write_be_uint(elt._1, 4u);
406410
write_fn(writer, elt._0);
@@ -458,7 +462,7 @@ fn encode_meta_item(&ebmlivec::writer ebml_w, &meta_item mi) {
458462
}
459463
}
460464

461-
fn encode_attributes(&ebmlivec::writer ebml_w, &vec[attribute] attrs) {
465+
fn encode_attributes(&ebmlivec::writer ebml_w, &attribute[] attrs) {
462466
ebmlivec::start_tag(ebml_w, tag_attributes);
463467
for (attribute attr in attrs) {
464468
ebmlivec::start_tag(ebml_w, tag_attribute);
@@ -473,7 +477,7 @@ fn encode_attributes(&ebmlivec::writer ebml_w, &vec[attribute] attrs) {
473477
// 'name' and 'vers' items, so if the user didn't provide them we will throw
474478
// them in anyway with default values.
475479
fn synthesize_crate_attrs(&@encode_ctxt ecx,
476-
&@crate crate) -> vec[attribute] {
480+
&@crate crate) -> attribute[] {
477481

478482
fn synthesize_link_attr(&@encode_ctxt ecx, &(@meta_item)[] items)
479483
-> attribute {
@@ -497,44 +501,44 @@ fn synthesize_crate_attrs(&@encode_ctxt ecx,
497501
ret attr::mk_attr(link_item);
498502
}
499503

500-
let vec[attribute] attrs = [];
504+
let attribute[] attrs = ~[];
501505
auto found_link_attr = false;
502506
for (attribute attr in crate.node.attrs) {
503507
attrs += if (attr::get_attr_name(attr) != "link") {
504-
[attr]
508+
~[attr]
505509
} else {
506510
alt (attr.node.value.node) {
507511
case (meta_list(?n, ?l)) {
508512
found_link_attr = true;
509-
[synthesize_link_attr(ecx, l)]
513+
~[synthesize_link_attr(ecx, l)]
510514
}
511-
case (_) { [attr] }
515+
case (_) { ~[attr] }
512516
}
513517
}
514518
}
515519

516520
if (!found_link_attr) {
517-
attrs += [synthesize_link_attr(ecx, ~[])];
521+
attrs += ~[synthesize_link_attr(ecx, ~[])];
518522
}
519523

520524
ret attrs;
521525
}
522526

523527
fn encode_crate_deps(&ebmlivec::writer ebml_w, &cstore::cstore cstore) {
524528

525-
fn get_ordered_names(&cstore::cstore cstore) -> vec[str] {
529+
fn get_ordered_names(&cstore::cstore cstore) -> str[] {
526530
type hashkv = @tup(crate_num, cstore::crate_metadata);
527531
type numname = tup(crate_num, str);
528532

529533
// Pull the cnums and names out of cstore
530-
let vec[mutable numname] pairs = [mutable];
534+
let numname[mutable] pairs = ~[mutable];
531535
for each (hashkv hashkv in cstore::iter_crate_data(cstore)) {
532-
pairs += [mutable tup(hashkv._0, hashkv._1.name)];
536+
pairs += ~[mutable tup(hashkv._0, hashkv._1.name)];
533537
}
534538

535539
// Sort by cnum
536540
fn lteq(&numname kv1, &numname kv2) -> bool { kv1._0 <= kv2._0 }
537-
std::sort::quick_sort(lteq, pairs);
541+
std::sort::ivector::quick_sort(lteq, pairs);
538542

539543
// Sanity-check the crate numbers
540544
auto expected_cnum = 1;
@@ -545,9 +549,9 @@ fn encode_crate_deps(&ebmlivec::writer ebml_w, &cstore::cstore cstore) {
545549

546550
// Return just the names
547551
fn name(&numname kv) -> str { kv._1 }
548-
// mutable -> immutable hack for vec::map
549-
auto immpairs = vec::slice(pairs, 0u, vec::len(pairs));
550-
ret vec::map(name, immpairs);
552+
// mutable -> immutable hack for ivec::map
553+
auto immpairs = ivec::slice(pairs, 0u, ivec::len(pairs));
554+
ret ivec::map(name, immpairs);
551555
}
552556

553557
// We're just going to write a list of crate names, with the assumption

0 commit comments

Comments
 (0)