File tree 3 files changed +27
-4
lines changed
librustc_codegen_llvm/back
3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -53,9 +53,7 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
53
53
54
54
let symbol_filter = & |& ( ref name, level) : & ( String , SymbolExportLevel ) | {
55
55
if level. is_below_threshold ( export_threshold) {
56
- let mut bytes = Vec :: with_capacity ( name. len ( ) + 1 ) ;
57
- bytes. extend ( name. bytes ( ) ) ;
58
- Some ( CString :: new ( bytes) . unwrap ( ) )
56
+ Some ( CString :: new ( name. as_str ( ) ) . unwrap ( ) )
59
57
} else {
60
58
None
61
59
}
Original file line number Diff line number Diff line change @@ -327,7 +327,31 @@ impl CString {
327
327
/// [`NulError`]: struct.NulError.html
328
328
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
329
329
pub fn new < T : Into < Vec < u8 > > > ( t : T ) -> Result < CString , NulError > {
330
- Self :: _new ( t. into ( ) )
330
+ trait SpecIntoVec {
331
+ fn into_vec ( self ) -> Vec < u8 > ;
332
+ }
333
+ impl < T : Into < Vec < u8 > > > SpecIntoVec for T {
334
+ default fn into_vec ( self ) -> Vec < u8 > {
335
+ self . into ( )
336
+ }
337
+ }
338
+ // Specialization for avoiding reallocation.
339
+ impl SpecIntoVec for & ' _ [ u8 ] {
340
+ fn into_vec ( self ) -> Vec < u8 > {
341
+ let mut v = Vec :: with_capacity ( self . len ( ) + 1 ) ;
342
+ v. extend ( self ) ;
343
+ v
344
+ }
345
+ }
346
+ impl SpecIntoVec for & ' _ str {
347
+ fn into_vec ( self ) -> Vec < u8 > {
348
+ let mut v = Vec :: with_capacity ( self . len ( ) + 1 ) ;
349
+ v. extend ( self . as_bytes ( ) ) ;
350
+ v
351
+ }
352
+ }
353
+
354
+ Self :: _new ( SpecIntoVec :: into_vec ( t) )
331
355
}
332
356
333
357
fn _new ( bytes : Vec < u8 > ) -> Result < CString , NulError > {
Original file line number Diff line number Diff line change 297
297
#![ feature( slice_concat_ext) ]
298
298
#![ feature( slice_internals) ]
299
299
#![ feature( slice_patterns) ]
300
+ #![ feature( specialization) ]
300
301
#![ feature( staged_api) ]
301
302
#![ feature( std_internals) ]
302
303
#![ feature( stdsimd) ]
You can’t perform that action at this time.
0 commit comments