@@ -93,11 +93,13 @@ thread_local! {
93
93
/// assert_eq!(current.get::<ValueB>(), None);
94
94
/// ```
95
95
#[ derive( Clone , Default ) ]
96
+ // 16-byte alignment for performance, which should be ok on 32-bit systems too
97
+ #[ repr( align( 16 ) ) ]
96
98
pub struct Context {
97
99
#[ cfg( feature = "trace" ) ]
98
100
pub ( crate ) span : Option < Arc < SynchronizedSpan > > ,
99
101
entries : Option < Arc < EntryMap > > ,
100
- suppress_telemetry : bool ,
102
+ flags : ContextFlags ,
101
103
}
102
104
103
105
type EntryMap = HashMap < TypeId , Arc < dyn Any + Sync + Send > , BuildHasherDefault < IdHasher > > ;
@@ -245,7 +247,7 @@ impl Context {
245
247
entries,
246
248
#[ cfg( feature = "trace" ) ]
247
249
span : self . span . clone ( ) ,
248
- suppress_telemetry : self . suppress_telemetry ,
250
+ flags : self . flags ,
249
251
}
250
252
}
251
253
@@ -335,7 +337,7 @@ impl Context {
335
337
/// Returns whether telemetry is suppressed in this context.
336
338
#[ inline]
337
339
pub fn is_telemetry_suppressed ( & self ) -> bool {
338
- self . suppress_telemetry
340
+ self . flags . is_telemetry_suppressed ( )
339
341
}
340
342
341
343
/// Returns a new context with telemetry suppression enabled.
@@ -344,7 +346,7 @@ impl Context {
344
346
entries : self . entries . clone ( ) ,
345
347
#[ cfg( feature = "trace" ) ]
346
348
span : self . span . clone ( ) ,
347
- suppress_telemetry : true ,
349
+ flags : self . flags . with_telemetry_suppressed ( ) ,
348
350
}
349
351
}
350
352
@@ -413,7 +415,7 @@ impl Context {
413
415
Self :: map_current ( |cx| Context {
414
416
span : Some ( Arc :: new ( value) ) ,
415
417
entries : cx. entries . clone ( ) ,
416
- suppress_telemetry : cx. suppress_telemetry ,
418
+ flags : cx. flags ,
417
419
} )
418
420
}
419
421
@@ -422,7 +424,7 @@ impl Context {
422
424
Context {
423
425
span : Some ( Arc :: new ( value) ) ,
424
426
entries : self . entries . clone ( ) ,
425
- suppress_telemetry : self . suppress_telemetry ,
427
+ flags : self . flags ,
426
428
}
427
429
}
428
430
}
@@ -446,7 +448,7 @@ impl fmt::Debug for Context {
446
448
let entries = self . entries . as_ref ( ) . map_or ( 0 , |e| e. len ( ) ) ;
447
449
448
450
dbg. field ( "entries count" , & entries)
449
- . field ( "suppress_telemetry" , & self . suppress_telemetry )
451
+ . field ( "suppress_telemetry" , & self . flags . is_telemetry_suppressed ( ) )
450
452
. finish ( )
451
453
}
452
454
}
@@ -605,6 +607,23 @@ impl Default for ContextStack {
605
607
}
606
608
}
607
609
610
+ #[ derive( Clone , Copy , Default ) ]
611
+ struct ContextFlags ( usize ) ;
612
+
613
+ impl ContextFlags {
614
+ const TELEMETRY_SUPPRESSED : usize = 1 ;
615
+
616
+ #[ inline( always) ]
617
+ fn is_telemetry_suppressed ( & self ) -> bool {
618
+ self . 0 & Self :: TELEMETRY_SUPPRESSED != 0
619
+ }
620
+
621
+ #[ inline( always) ]
622
+ fn with_telemetry_suppressed ( & self ) -> Self {
623
+ Self ( self . 0 | Self :: TELEMETRY_SUPPRESSED )
624
+ }
625
+ }
626
+
608
627
#[ cfg( test) ]
609
628
mod tests {
610
629
use super :: * ;
0 commit comments