@@ -225,11 +225,12 @@ fn fat_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
225
225
// and we want to move everything to the same LLVM context. Currently the
226
226
// way we know of to do that is to serialize them to a string and them parse
227
227
// 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| {
229
229
let buffer = ModuleBuffer :: new ( module. module_llvm . llmod ( ) ) ;
230
230
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
+ } ) ) ;
233
234
234
235
// For all serialized bitcode files we parse them and link them in as we did
235
236
// above, this is all mostly handled in C++. Like above, though, we don't
@@ -349,9 +350,10 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
349
350
. map ( |& ( _, ref wp) | ( wp. cgu_name . clone ( ) , wp. clone ( ) ) )
350
351
. collect ( ) ;
351
352
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) ;
355
357
356
358
// FIXME: right now, like with fat LTO, we serialize all in-memory
357
359
// modules before working with them and ThinLTO. We really
@@ -360,7 +362,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
360
362
// into the global index. It turns out that this loop is by far
361
363
// the most expensive portion of this small bit of global
362
364
// analysis!
363
- for ( i, module) in modules. iter ( ) . enumerate ( ) {
365
+ for ( i, module) in modules. into_iter ( ) . enumerate ( ) {
364
366
info ! ( "local module: {} - {}" , i, module. name) ;
365
367
let name = CString :: new ( module. name . clone ( ) ) . unwrap ( ) ;
366
368
let buffer = ThinBuffer :: new ( module. module_llvm . llmod ( ) ) ;
@@ -406,7 +408,7 @@ fn thin_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
406
408
// incremental ThinLTO first where we could actually avoid
407
409
// looking at upstream modules entirely sometimes (the contents,
408
410
// 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 ( ) ) ;
410
412
411
413
let cached_modules = cached_modules. into_iter ( ) . map ( |( sm, wp) | {
412
414
( sm, CString :: new ( wp. cgu_name ) . unwrap ( ) )
0 commit comments