@@ -99,12 +99,18 @@ pub struct FilterId(u64);
99
99
///
100
100
/// [`Registry`]: crate::Registry
101
101
/// [`Filter`]: crate::layer::Filter
102
- #[ derive( Default , Copy , Clone , Eq , PartialEq ) ]
102
+ #[ derive( Copy , Clone , Eq , PartialEq ) ]
103
103
pub ( crate ) struct FilterMap {
104
104
bits : u64 ,
105
105
}
106
106
107
- /// The current state of `enabled` calls to per-layer filters on this
107
+ impl FilterMap {
108
+ pub ( crate ) const fn new ( ) -> Self {
109
+ Self { bits : 0 }
110
+ }
111
+ }
112
+
113
+ /// The current state of `enabled` calls to per-subscriber filters on this
108
114
/// thread.
109
115
///
110
116
/// When `Filtered::enabled` is called, the filter will set the bit
@@ -145,7 +151,7 @@ pub(crate) struct FilterState {
145
151
146
152
/// Extra counters added to `FilterState` used only to make debug assertions.
147
153
#[ cfg( debug_assertions) ]
148
- #[ derive( Debug , Default ) ]
154
+ #[ derive( Debug ) ]
149
155
struct DebugCounters {
150
156
/// How many per-layer filters have participated in the current `enabled`
151
157
/// call?
@@ -156,8 +162,18 @@ struct DebugCounters {
156
162
in_interest_pass : Cell < usize > ,
157
163
}
158
164
165
+ #[ cfg( debug_assertions) ]
166
+ impl DebugCounters {
167
+ const fn new ( ) -> Self {
168
+ Self {
169
+ in_filter_pass : Cell :: new ( 0 ) ,
170
+ in_interest_pass : Cell :: new ( 0 ) ,
171
+ }
172
+ }
173
+ }
174
+
159
175
thread_local ! {
160
- pub ( crate ) static FILTERING : FilterState = FilterState :: new( ) ;
176
+ pub ( crate ) static FILTERING : FilterState = const { FilterState :: new( ) } ;
161
177
}
162
178
163
179
/// Extension trait adding [combinators] for combining [`Filter`].
@@ -1080,13 +1096,13 @@ impl fmt::Binary for FilterMap {
1080
1096
// === impl FilterState ===
1081
1097
1082
1098
impl FilterState {
1083
- fn new ( ) -> Self {
1099
+ const fn new ( ) -> Self {
1084
1100
Self {
1085
- enabled : Cell :: new ( FilterMap :: default ( ) ) ,
1101
+ enabled : Cell :: new ( FilterMap :: new ( ) ) ,
1086
1102
interest : RefCell :: new ( None ) ,
1087
1103
1088
1104
#[ cfg( debug_assertions) ]
1089
- counters : DebugCounters :: default ( ) ,
1105
+ counters : DebugCounters :: new ( ) ,
1090
1106
}
1091
1107
}
1092
1108
@@ -1095,7 +1111,7 @@ impl FilterState {
1095
1111
{
1096
1112
let in_current_pass = self . counters . in_filter_pass . get ( ) ;
1097
1113
if in_current_pass == 0 {
1098
- debug_assert_eq ! ( self . enabled. get( ) , FilterMap :: default ( ) ) ;
1114
+ debug_assert_eq ! ( self . enabled. get( ) , FilterMap :: new ( ) ) ;
1099
1115
}
1100
1116
self . counters . in_filter_pass . set ( in_current_pass + 1 ) ;
1101
1117
debug_assert_eq ! (
@@ -1140,7 +1156,7 @@ impl FilterState {
1140
1156
#[ cfg( debug_assertions) ]
1141
1157
{
1142
1158
if this. counters . in_filter_pass . get ( ) == 0 {
1143
- debug_assert_eq ! ( this. enabled. get( ) , FilterMap :: default ( ) ) ;
1159
+ debug_assert_eq ! ( this. enabled. get( ) , FilterMap :: new ( ) ) ;
1144
1160
}
1145
1161
1146
1162
// Nothing enabled this event, we won't tick back down the
@@ -1177,7 +1193,7 @@ impl FilterState {
1177
1193
{
1178
1194
let in_current_pass = self . counters . in_filter_pass . get ( ) ;
1179
1195
if in_current_pass <= 1 {
1180
- debug_assert_eq ! ( self . enabled. get( ) , FilterMap :: default ( ) ) ;
1196
+ debug_assert_eq ! ( self . enabled. get( ) , FilterMap :: new ( ) ) ;
1181
1197
}
1182
1198
self . counters
1183
1199
. in_filter_pass
@@ -1207,7 +1223,7 @@ impl FilterState {
1207
1223
// a panic and the thread-local has been torn down, that's fine, just
1208
1224
// ignore it ratehr than panicking.
1209
1225
let _ = FILTERING . try_with ( |filtering| {
1210
- filtering. enabled . set ( FilterMap :: default ( ) ) ;
1226
+ filtering. enabled . set ( FilterMap :: new ( ) ) ;
1211
1227
1212
1228
#[ cfg( debug_assertions) ]
1213
1229
filtering. counters . in_filter_pass . set ( 0 ) ;
@@ -1232,10 +1248,8 @@ impl FilterState {
1232
1248
pub ( crate ) fn filter_map ( & self ) -> FilterMap {
1233
1249
let map = self . enabled . get ( ) ;
1234
1250
#[ cfg( debug_assertions) ]
1235
- {
1236
- if self . counters . in_filter_pass . get ( ) == 0 {
1237
- debug_assert_eq ! ( map, FilterMap :: default ( ) ) ;
1238
- }
1251
+ if self . counters . in_filter_pass . get ( ) == 0 {
1252
+ debug_assert_eq ! ( map, FilterMap :: new( ) ) ;
1239
1253
}
1240
1254
1241
1255
map
0 commit comments