@@ -457,32 +457,32 @@ mod write {
457457 *
458458 */
459459
460- fn build_link_meta ( sess : Session , c : ast:: crate , output : & Path ,
460+ fn build_link_meta ( sess : Session , c : & ast:: crate , output : & Path ,
461461 symbol_hasher : & hash:: State ) -> link_meta {
462462
463463 type provided_metas =
464- { name : Option < ~ str > ,
465- vers : Option < ~ str > ,
464+ { name : Option < @ str > ,
465+ vers : Option < @ str > ,
466466 cmh_items : ~[ @ast:: meta_item ] } ;
467467
468- fn provided_link_metas ( sess : Session , c : ast:: crate ) ->
468+ fn provided_link_metas ( sess : Session , c : & ast:: crate ) ->
469469 provided_metas {
470- let mut name: Option < ~str > = None ;
471- let mut vers: Option < ~str > = None ;
472- let mut cmh_items: ~[ @ast:: meta_item ] = ~[ ] ;
473- let linkage_metas =
474- attr:: find_linkage_metas ( /*bad*/ copy c. node . attrs ) ;
475- // XXX: Bad copy.
476- attr:: require_unique_names ( sess. diagnostic ( ) , copy linkage_metas) ;
470+ let mut name = None ;
471+ let mut vers = None ;
472+ let mut cmh_items = ~[ ] ;
473+ let linkage_metas = attr:: find_linkage_metas ( c. node . attrs ) ;
474+ attr:: require_unique_names ( sess. diagnostic ( ) , linkage_metas) ;
477475 for linkage_metas. each |meta| {
478476 if attr:: get_meta_item_name ( * meta) == ~"name" {
479477 match attr:: get_meta_item_value_str ( * meta) {
480- Some ( ref v) => { name = Some ( ( /*bad*/ copy * v) ) ; }
478+ // Changing attr would avoid the need for the copy
479+ // here
480+ Some ( v) => { name = Some ( v. to_managed ( ) ) ; }
481481 None => cmh_items. push ( * meta)
482482 }
483483 } else if attr:: get_meta_item_name ( * meta) == ~"vers" {
484484 match attr:: get_meta_item_value_str ( * meta) {
485- Some ( ref v) => { vers = Some ( ( /*bad*/ copy * v ) ) ; }
485+ Some ( v) => { vers = Some ( v . to_managed ( ) ) ; }
486486 None => cmh_items. push ( * meta)
487487 }
488488 } else { cmh_items. push ( * meta) ; }
@@ -492,9 +492,8 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
492492
493493 // This calculates CMH as defined above
494494 fn crate_meta_extras_hash ( symbol_hasher : & hash:: State ,
495- _crate : ast:: crate ,
496- metas : provided_metas ,
497- dep_hashes : ~[ ~str ] ) -> ~str {
495+ -cmh_items : ~[ @ast:: meta_item ] ,
496+ dep_hashes : ~[ ~str ] ) -> @str {
498497 fn len_and_str ( s : ~str ) -> ~str {
499498 return fmt ! ( "%u_%s" , str :: len( s) , s) ;
500499 }
@@ -503,7 +502,7 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
503502 return len_and_str ( pprust:: lit_to_str ( @l) ) ;
504503 }
505504
506- let cmh_items = attr:: sort_meta_items ( /*bad*/ copy metas . cmh_items ) ;
505+ let cmh_items = attr:: sort_meta_items ( cmh_items) ;
507506
508507 symbol_hasher. reset ( ) ;
509508 for cmh_items. each |m| {
@@ -526,52 +525,53 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
526525 symbol_hasher. write_str ( len_and_str ( * dh) ) ;
527526 }
528527
529- return truncated_hash_result ( symbol_hasher) ;
528+ // tjc: allocation is unfortunate; need to change core::hash
529+ return truncated_hash_result ( symbol_hasher) . to_managed ( ) ;
530530 }
531531
532- fn warn_missing ( sess : Session , name : ~ str , default : ~ str ) {
532+ fn warn_missing ( sess : Session , name : & str , default : & str ) {
533533 if !sess. building_library { return ; }
534534 sess. warn ( fmt ! ( "missing crate link meta `%s`, using `%s` as default" ,
535535 name, default ) ) ;
536536 }
537537
538- fn crate_meta_name ( sess : Session , _crate : ast :: crate ,
539- output : & Path , metas : provided_metas ) -> ~ str {
540- return match metas . name {
541- Some ( ref v) => ( /*bad*/ copy * v ) ,
538+ fn crate_meta_name ( sess : Session , output : & Path , - opt_name : Option < @ str > )
539+ -> @ str {
540+ return match opt_name {
541+ Some ( v) => v ,
542542 None => {
543- let name = match output. filestem ( ) {
544- None => sess. fatal ( fmt ! ( "output file name `%s` doesn't\
543+ // to_managed could go away if there was a version of
544+ // filestem that returned an @str
545+ let name = session:: expect ( sess,
546+ output. filestem ( ) ,
547+ || fmt ! ( "output file name `%s` doesn't\
545548 appear to have a stem",
546- output. to_str( ) ) ) ,
547- Some ( ref s) => ( /*bad*/ copy * s)
548- } ;
549- // XXX: Bad copy.
550- warn_missing ( sess, ~"name", copy name) ;
549+ output. to_str( ) ) ) . to_managed ( ) ;
550+ warn_missing ( sess, ~"name", name) ;
551551 name
552552 }
553553 } ;
554554 }
555555
556- fn crate_meta_vers ( sess : Session , _crate : ast:: crate ,
557- metas : provided_metas ) -> ~str {
558- return match metas. vers {
559- Some ( ref v) => ( /*bad*/ copy * v) ,
556+ fn crate_meta_vers ( sess : Session , opt_vers : Option < @str > ) -> @str {
557+ return match opt_vers {
558+ Some ( v) => v,
560559 None => {
561- let vers = ~"0.0 ";
562- // Bad copy.
563- warn_missing ( sess, ~"vers", copy vers) ;
560+ let vers = @"0.0 ";
561+ warn_missing ( sess, ~"vers", vers) ;
564562 vers
565563 }
566564 } ;
567565 }
568566
569- let provided_metas = provided_link_metas ( sess, c) ;
570- let name = crate_meta_name ( sess, c, output, provided_metas) ;
571- let vers = crate_meta_vers ( sess, c, provided_metas) ;
567+ let { name: opt_name , vers: opt_vers ,
568+ cmh_items : cmh_items } = provided_link_metas ( sess, c) ;
569+ let name = crate_meta_name ( sess, output, move opt_name) ;
570+ let vers = crate_meta_vers ( sess, move opt_vers) ;
572571 let dep_hashes = cstore:: get_dep_hashes ( sess. cstore ) ;
573572 let extras_hash =
574- crate_meta_extras_hash ( symbol_hasher, c, provided_metas, dep_hashes) ;
573+ crate_meta_extras_hash ( symbol_hasher, move cmh_items,
574+ dep_hashes) ;
575575
576576 return { name: name, vers: vers, extras_hash: extras_hash} ;
577577}
@@ -583,7 +583,7 @@ fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str unsafe {
583583
584584// This calculates STH for a symbol, as defined above
585585fn symbol_hash( tcx : ty:: ctxt , symbol_hasher : & hash:: State , t : ty:: t ,
586- link_meta : link_meta ) -> ~ str {
586+ link_meta : link_meta ) -> @ str {
587587 // NB: do *not* use abbrevs here as we want the symbol names
588588 // to be independent of one another in the crate.
589589
@@ -593,20 +593,20 @@ fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
593593 symbol_hasher.write_str(link_meta.extras_hash);
594594 symbol_hasher.write_str(~" -");
595595 symbol_hasher.write_str(encoder::encoded_ty(tcx, t));
596- let hash = truncated_hash_result(symbol_hasher);
596+ let mut hash = truncated_hash_result(symbol_hasher);
597597 // Prefix with _ so that it never blends into adjacent digits
598-
599- return ~" _" + hash;
598+ str::unshift_char(&mut hash, '_');
599+ // tjc: allocation is unfortunate; need to change core::hash
600+ hash.to_managed()
600601}
601602
602- fn get_symbol_hash ( ccx : @crate_ctxt , t : ty:: t ) -> ~ str {
603+ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> @ str {
603604 match ccx.type_hashcodes.find(t) {
604- Some ( ref h) => return ( /*bad*/ copy * h ) ,
605+ Some(h) => h ,
605606 None => {
606607 let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
607- // XXX: Bad copy. Prefer `@str`?
608- ccx. type_hashcodes . insert ( t, copy hash) ;
609- return hash;
608+ ccx.type_hashcodes.insert(t, hash);
609+ hash
610610 }
611611 }
612612}
@@ -664,30 +664,30 @@ fn mangle(sess: Session, ss: path) -> ~str {
664664
665665fn exported_name ( sess : Session ,
666666 +path : path,
667- + hash : ~ str ,
668- + vers : ~ str ) -> ~str {
667+ hash : & str ,
668+ vers : & str ) -> ~str {
669669 return mangle ( sess,
670- vec:: append_one (
671- vec:: append_one ( path, path_name ( sess. ident_of ( hash) ) ) ,
672- path_name ( sess. ident_of ( vers) ) ) ) ;
670+ vec:: append_one (
671+ vec:: append_one ( path, path_name ( sess. ident_of ( hash. to_owned ( ) ) ) ) ,
672+ path_name ( sess. ident_of ( vers. to_owned ( ) ) ) ) ) ;
673673}
674674
675675fn mangle_exported_name ( ccx : @crate_ctxt , +path : path, t : ty:: t ) -> ~str {
676676 let hash = get_symbol_hash ( ccx, t) ;
677677 return exported_name ( ccx. sess , path,
678678 hash,
679- /*bad*/ copy ccx. link_meta . vers ) ;
679+ ccx. link_meta . vers ) ;
680680}
681681
682682fn mangle_internal_name_by_type_only ( ccx : @crate_ctxt ,
683683 t : ty:: t ,
684- + name : ~ str ) -> ~str {
684+ name : & str ) -> ~str {
685685 let s = ppaux:: ty_to_short_str ( ccx. tcx , t) ;
686686 let hash = get_symbol_hash ( ccx, t) ;
687687 return mangle ( ccx. sess ,
688- ~[ path_name ( ccx. sess . ident_of ( name) ) ,
689- path_name ( ccx. sess . ident_of ( s) ) ,
690- path_name ( ccx. sess . ident_of ( hash) ) ] ) ;
688+ ~[ path_name ( ccx. sess . ident_of ( name. to_owned ( ) ) ) ,
689+ path_name ( ccx. sess . ident_of ( s) ) ,
690+ path_name ( ccx. sess . ident_of ( hash. to_owned ( ) ) ) ] ) ;
691691}
692692
693693fn mangle_internal_name_by_path_and_seq ( ccx : @crate_ctxt ,
@@ -706,7 +706,7 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
706706}
707707
708708
709- fn output_dll_filename ( os : session:: os , lm : & link_meta ) -> ~str {
709+ fn output_dll_filename ( os : session:: os , lm : link_meta ) -> ~str {
710710 let libname = fmt ! ( "%s-%s-%s" , lm. name, lm. extras_hash, lm. vers) ;
711711 let ( dll_prefix, dll_suffix) = match os {
712712 session:: os_win32 => ( win32:: DLL_PREFIX , win32:: DLL_SUFFIX ) ,
@@ -736,7 +736,7 @@ fn link_binary(sess: Session,
736736 }
737737
738738 let output = if sess. building_library {
739- let long_libname = output_dll_filename ( sess. targ_cfg . os , & lm) ;
739+ let long_libname = output_dll_filename ( sess. targ_cfg . os , lm) ;
740740 debug ! ( "link_meta.name: %s" , lm. name) ;
741741 debug ! ( "long_libname: %s" , long_libname) ;
742742 debug ! ( "out_filename: %s" , out_filename. to_str( ) ) ;
0 commit comments