@@ -162,14 +162,13 @@ fn item_visibility(item: ebml::Doc) -> ast::visibility {
162
162
163
163
fn item_method_sort ( item : ebml:: Doc ) -> char {
164
164
for reader:: tagged_docs( item, tag_item_trait_method_sort) |doc| {
165
- return str :: from_bytes ( reader :: doc_data ( doc) ) [ 0 ] as char;
165
+ return doc. as_str_slice ( ) [ 0 ] as char ;
166
166
}
167
167
return 'r' ;
168
168
}
169
169
170
170
fn item_symbol ( item : ebml:: Doc ) -> ~str {
171
- let sym = reader:: get_doc ( item, tag_items_data_item_symbol) ;
172
- return str:: from_bytes ( reader:: doc_data ( sym) ) ;
171
+ reader:: get_doc ( item, tag_items_data_item_symbol) . as_str ( )
173
172
}
174
173
175
174
fn item_parent_item ( d : ebml:: Doc ) -> Option < ast:: def_id > {
@@ -209,7 +208,7 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) -> bool {
209
208
210
209
fn variant_disr_val ( d : ebml:: Doc ) -> Option < int > {
211
210
do reader:: maybe_get_doc ( d, tag_disr_val) . chain |val_doc| {
212
- int :: parse_bytes ( reader:: doc_data ( val_doc) , 10 u)
211
+ do reader:: with_doc_data ( val_doc) |data| { int :: parse_bytes ( data , 10 u) }
213
212
}
214
213
}
215
214
@@ -296,10 +295,10 @@ fn item_path(item_doc: ebml::Doc) -> ast_map::path {
296
295
let mut result = vec:: with_capacity ( len) ;
297
296
for reader:: docs( path_doc) |tag, elt_doc| {
298
297
if tag == tag_path_elt_mod {
299
- let str = reader :: doc_as_str ( elt_doc) ;
298
+ let str = elt_doc. as_str_slice ( ) ;
300
299
result. push ( ast_map:: path_mod ( token:: str_to_ident ( str) ) ) ;
301
300
} else if tag == tag_path_elt_name {
302
- let str = reader :: doc_as_str ( elt_doc) ;
301
+ let str = elt_doc. as_str_slice ( ) ;
303
302
result. push ( ast_map:: path_name ( token:: str_to_ident ( str) ) ) ;
304
303
} else {
305
304
// ignore tag_path_len element
@@ -311,12 +310,10 @@ fn item_path(item_doc: ebml::Doc) -> ast_map::path {
311
310
312
311
fn item_name ( intr : @ident_interner , item : ebml:: Doc ) -> ast:: ident {
313
312
let name = reader:: get_doc ( item, tag_paths_data_name) ;
314
- do reader:: with_doc_data ( name) |data| {
315
- let string = str:: from_bytes_slice ( data) ;
316
- match intr. find_equiv ( & StringRef ( string) ) {
317
- None => token:: str_to_ident ( string) ,
318
- Some ( val) => ast:: new_ident ( val) ,
319
- }
313
+ let string = name. as_str_slice ( ) ;
314
+ match intr. find_equiv ( & StringRef ( string) ) {
315
+ None => token:: str_to_ident ( string) ,
316
+ Some ( val) => ast:: new_ident ( val) ,
320
317
}
321
318
}
322
319
@@ -506,19 +503,17 @@ pub fn each_path(intr: @ident_interner,
506
503
let def_id_doc =
507
504
reader:: get_doc ( reexport_doc,
508
505
tag_items_data_item_reexport_def_id) ;
509
- let def_id =
510
- reader:: with_doc_data ( def_id_doc,
511
- |d| parse_def_id ( d) ) ;
506
+ let def_id = reader:: with_doc_data ( def_id_doc, parse_def_id) ;
512
507
let def_id = translate_def_id ( cdata, def_id) ;
513
508
514
509
let reexport_name_doc =
515
510
reader:: get_doc ( reexport_doc,
516
511
tag_items_data_item_reexport_name) ;
517
- let reexport_name = reader :: doc_as_str ( reexport_name_doc) ;
512
+ let reexport_name = reexport_name_doc. as_str_slice ( ) ;
518
513
519
514
let reexport_path;
520
515
if path_is_empty {
521
- reexport_path = reexport_name;
516
+ reexport_path = reexport_name. to_owned ( ) ;
522
517
} else {
523
518
reexport_path = path + "::" + reexport_name;
524
519
}
@@ -639,7 +634,7 @@ fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
639
634
}
640
635
641
636
let explicit_self_doc = reader:: get_doc ( item, tag_item_trait_method_explicit_self) ;
642
- let string = reader :: doc_as_str ( explicit_self_doc) ;
637
+ let string = explicit_self_doc. as_str_slice ( ) ;
643
638
644
639
let explicit_self_kind = string[ 0 ] ;
645
640
match explicit_self_kind as char {
@@ -824,7 +819,7 @@ pub fn get_type_name_if_impl(cdata: cmd,
824
819
}
825
820
826
821
for reader:: tagged_docs( item, tag_item_impl_type_basename) |doc| {
827
- return Some ( token:: str_to_ident( str :: from_bytes ( reader :: doc_data ( doc) ) ) ) ;
822
+ return Some ( token:: str_to_ident ( doc. as_str_slice ( ) ) ) ;
828
823
}
829
824
830
825
return None ;
@@ -846,7 +841,7 @@ pub fn get_static_methods_if_impl(intr: @ident_interner,
846
841
847
842
let mut impl_method_ids = ~[ ] ;
848
843
for reader:: tagged_docs( item, tag_item_impl_method) |impl_method_doc| {
849
- impl_method_ids. push ( parse_def_id ( reader:: doc_data ( impl_method_doc) ) ) ;
844
+ impl_method_ids. push ( reader:: with_doc_data ( impl_method_doc, parse_def_id ) ) ;
850
845
}
851
846
852
847
let mut static_impl_methods = ~[ ] ;
@@ -943,12 +938,13 @@ fn family_names_type(fam: Family) -> bool {
943
938
}
944
939
945
940
fn read_path ( d : ebml:: Doc ) -> ( ~str , uint ) {
946
- let desc = reader:: doc_data ( d) ;
947
- let pos = io:: u64_from_be_bytes ( desc, 0 u, 4 u) as uint ;
948
- let pathbytes = vec :: slice :: < u8 > ( desc , 4 u, vec :: len :: < u8 > ( desc ) ) ;
949
- let path = str:: from_bytes ( pathbytes) ;
941
+ do reader:: with_doc_data ( d) |desc| {
942
+ let pos = io:: u64_from_be_bytes ( desc, 0 u, 4 u) as uint ;
943
+ let pathbytes = desc . slice ( 4 u, desc . len ( ) ) ;
944
+ let path = str:: from_bytes ( pathbytes) ;
950
945
951
- ( path, pos)
946
+ ( path, pos)
947
+ }
952
948
}
953
949
954
950
fn describe_def ( items : ebml:: Doc , id : ast:: def_id ) -> ~str {
@@ -989,21 +985,21 @@ fn get_meta_items(md: ebml::Doc) -> ~[@ast::meta_item] {
989
985
let mut items: ~[ @ast:: meta_item ] = ~[ ] ;
990
986
for reader:: tagged_docs( md, tag_meta_item_word) |meta_item_doc| {
991
987
let nd = reader:: get_doc ( meta_item_doc, tag_meta_item_name) ;
992
- let n = str :: from_bytes ( reader :: doc_data ( nd ) ) ;
988
+ let n = nd . as_str ( ) ;
993
989
items. push ( attr:: mk_word_item ( @n) ) ;
994
990
} ;
995
991
for reader:: tagged_docs( md, tag_meta_item_name_value) |meta_item_doc| {
996
992
let nd = reader:: get_doc ( meta_item_doc, tag_meta_item_name) ;
997
993
let vd = reader:: get_doc ( meta_item_doc, tag_meta_item_value) ;
998
- let n = str :: from_bytes ( reader :: doc_data ( nd ) ) ;
999
- let v = str :: from_bytes ( reader :: doc_data ( vd ) ) ;
994
+ let n = nd . as_str ( ) ;
995
+ let v = vd . as_str ( ) ;
1000
996
// FIXME (#623): Should be able to decode meta_name_value variants,
1001
997
// but currently the encoder just drops them
1002
998
items. push ( attr:: mk_name_value_item_str ( @n, @v) ) ;
1003
999
} ;
1004
1000
for reader:: tagged_docs( md, tag_meta_item_list) |meta_item_doc| {
1005
1001
let nd = reader:: get_doc ( meta_item_doc, tag_meta_item_name) ;
1006
- let n = str :: from_bytes ( reader :: doc_data ( nd ) ) ;
1002
+ let n = nd . as_str ( ) ;
1007
1003
let subitems = get_meta_items ( meta_item_doc) ;
1008
1004
items. push ( attr:: mk_list_item ( @n, subitems) ) ;
1009
1005
} ;
@@ -1072,7 +1068,7 @@ pub fn get_crate_deps(data: @~[u8]) -> ~[crate_dep] {
1072
1068
let depsdoc = reader:: get_doc ( cratedoc, tag_crate_deps) ;
1073
1069
let mut crate_num = 1 ;
1074
1070
fn docstr ( doc : ebml:: Doc , tag_ : uint ) -> ~str {
1075
- str :: from_bytes ( reader:: doc_data ( reader :: get_doc ( doc, tag_) ) )
1071
+ reader:: get_doc ( doc, tag_) . as_str ( )
1076
1072
}
1077
1073
for reader:: tagged_docs( depsdoc, tag_crate_dep) |depdoc| {
1078
1074
deps. push ( crate_dep { cnum : crate_num,
@@ -1099,7 +1095,7 @@ fn list_crate_deps(data: @~[u8], out: @io::Writer) {
1099
1095
pub fn get_crate_hash ( data : @~[ u8 ] ) -> @~str {
1100
1096
let cratedoc = reader:: Doc ( data) ;
1101
1097
let hashdoc = reader:: get_doc ( cratedoc, tag_crate_hash) ;
1102
- @str :: from_bytes ( reader :: doc_data ( hashdoc) )
1098
+ @hashdoc. as_str ( )
1103
1099
}
1104
1100
1105
1101
pub fn get_crate_vers ( data : @~[ u8 ] ) -> @~str {
@@ -1154,7 +1150,7 @@ pub fn get_link_args_for_crate(cdata: cmd) -> ~[~str] {
1154
1150
let link_args = reader:: get_doc ( reader:: Doc ( cdata. data ) , tag_link_args) ;
1155
1151
let mut result = ~[ ] ;
1156
1152
for reader:: tagged_docs( link_args, tag_link_args_arg) |arg_doc| {
1157
- result. push ( reader :: doc_as_str ( arg_doc) ) ;
1153
+ result. push ( arg_doc. as_str ( ) ) ;
1158
1154
}
1159
1155
result
1160
1156
}
0 commit comments