@@ -225,11 +225,12 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
225225 // and we want to move everything to the same LLVM context. Currently the
226226 // way we know of to do that is to serialize them to a string and them parse
227227 // them later. Not great but hey, that's why it's "fat" LTO, right?
228- for module in modules {
228+ serialized_modules . extend ( modules. into_iter ( ) . map ( |module| {
229229 let buffer = ModuleBuffer :: new ( module. module_llvm . llmod ( ) ) ;
230230 let llmod_id = CString :: new ( & module. name [ ..] ) . unwrap ( ) ;
231- serialized_modules. push ( ( SerializedModule :: Local ( buffer) , llmod_id) ) ;
232- }
231+
232+ ( SerializedModule :: Local ( buffer) , llmod_id)
233+ } ) ) ;
233234
234235 // For all serialized bitcode files we parse them and link them in as we did
235236 // above, this is all mostly handled in C++. Like above, though, we don't
@@ -349,9 +350,10 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
349350 . map ( |& ( _, ref wp) | ( wp. cgu_name . clone ( ) , wp. clone ( ) ) )
350351 . collect ( ) ;
351352
352- let mut thin_buffers = Vec :: new ( ) ;
353- let mut module_names = Vec :: new ( ) ;
354- let mut thin_modules = Vec :: new ( ) ;
353+ let full_scope_len = modules. len ( ) + serialized_modules. len ( ) + cached_modules. len ( ) ;
354+ let mut thin_buffers = Vec :: with_capacity ( modules. len ( ) ) ;
355+ let mut module_names = Vec :: with_capacity ( full_scope_len) ;
356+ let mut thin_modules = Vec :: with_capacity ( full_scope_len) ;
355357
356358 // FIXME: right now, like with fat LTO, we serialize all in-memory
357359 // modules before working with them and ThinLTO. We really
@@ -360,7 +362,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
360362 // into the global index. It turns out that this loop is by far
361363 // the most expensive portion of this small bit of global
362364 // analysis!
363- for ( i, module) in modules. iter ( ) . enumerate ( ) {
365+ for ( i, module) in modules. into_iter ( ) . enumerate ( ) {
364366 info ! ( "local module: {} - {}" , i, module. name) ;
365367 let name = CString :: new ( module. name . clone ( ) ) . unwrap ( ) ;
366368 let buffer = ThinBuffer :: new ( module. module_llvm . llmod ( ) ) ;
@@ -406,7 +408,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
406408 // incremental ThinLTO first where we could actually avoid
407409 // looking at upstream modules entirely sometimes (the contents,
408410 // we must always unconditionally look at the index).
409- let mut serialized = Vec :: new ( ) ;
411+ let mut serialized = Vec :: with_capacity ( serialized_modules . len ( ) + cached_modules . len ( ) ) ;
410412
411413 let cached_modules = cached_modules. into_iter ( ) . map ( |( sm, wp) | {
412414 ( sm, CString :: new ( wp. cgu_name ) . unwrap ( ) )
0 commit comments