@@ -151,7 +151,13 @@ pub(crate) fn disallow_cfgs(sess: &Session, user_cfgs: &Cfg) {
151
151
152
152
/// Generate the default configs for a given session
153
153
pub ( crate ) fn default_configuration ( sess : & Session ) -> Cfg {
154
+ // As of 2025-02-14 a default `x86_64-unknown-linux-gnu` has ~20 cfgs.
155
+ //
156
+ // So let's round that up to 32 to avoid allocating unnecessarely and to
157
+ // give a bit a wigle room for the various options and cfgs that might
158
+ // affect the list of cfgs.
154
159
let mut ret = Cfg :: default ( ) ;
160
+ ret. reserve ( 32 ) ;
155
161
156
162
macro_rules! ins_none {
157
163
( $key: expr) => {
@@ -310,6 +316,11 @@ impl CheckCfg {
310
316
return ;
311
317
}
312
318
319
+ // As of 2025-02-14 there are 30 well known cfg, so pre-allocate
320
+ // at least that much.
321
+ self . well_known_names . reserve ( 30 ) ;
322
+ self . expecteds . reserve ( 30 ) ;
323
+
313
324
// for `#[cfg(foo)]` (ie. cfg value is none)
314
325
let no_values = || {
315
326
let mut values = FxHashSet :: default ( ) ;
@@ -400,18 +411,27 @@ impl CheckCfg {
400
411
& sym:: target_vendor,
401
412
] ;
402
413
414
+ // As of 2025-02-14 the maximum number of values is 41 in `target_os`
415
+ // so allocate at least that much.
416
+ // FIXME: Be more granular as not all `taregt_*` cfg have that much values.
417
+ let target_values = || {
418
+ let mut values = FxHashSet :: default ( ) ;
419
+ values. reserve ( 41 ) ;
420
+ ExpectedValues :: Some ( values)
421
+ } ;
422
+
403
423
// Initialize (if not already initialized)
404
424
for & e in VALUES {
405
425
if !self . exhaustive_values {
406
426
ins ! ( e, || ExpectedValues :: Any ) ;
407
427
} else {
408
- ins ! ( e, empty_values ) ;
428
+ ins ! ( e, target_values ) ;
409
429
}
410
430
}
411
431
412
432
if self . exhaustive_values {
413
- // Get all values map at once otherwise it would be costly.
414
- // (8 values * 220 targets ~= 1760 times, at the time of writing this comment).
433
+ // Get all values map at once otherwise it would be _very_ costly.
434
+ // (8 values * 287 targets ~= 2300 times, at the time of writing this comment).
415
435
let [
416
436
Some ( values_target_abi) ,
417
437
Some ( values_target_arch) ,
0 commit comments