@@ -227,43 +227,37 @@ private static ActivityEvent CreateActivityEvent(
227
227
228
228
private IDictionary < string , double > ? GetEventMeasures ( IDictionary < string , double > ? measurements )
229
229
{
230
- if ( measurements is null )
230
+ return ( measurements , _commonMeasurements ) switch
231
231
{
232
- return _commonMeasurements ;
233
- }
234
- if ( _commonMeasurements == null )
235
- {
236
- return measurements ;
237
- }
232
+ ( null , null ) => null ,
233
+ ( null , not null ) => _commonMeasurements == FrozenDictionary < string , double > . Empty ? null : new Dictionary < string , double > ( _commonMeasurements ) ,
234
+ ( not null , null ) => measurements ,
235
+ ( not null , not null ) => Combine ( _commonMeasurements , measurements ) ,
236
+ } ;
237
+ }
238
238
239
- IDictionary < string , double > eventMeasurements = new Dictionary < string , double > ( _commonMeasurements ) ;
240
- foreach ( KeyValuePair < string , double > measurement in measurements )
239
+ private IDictionary < string , string > ? GetEventProperties ( IDictionary < string , string > ? properties )
240
+ {
241
+ return ( properties , _commonProperties ) switch
241
242
{
242
- eventMeasurements [ measurement . Key ] = measurement . Value ;
243
- }
244
- return eventMeasurements ;
243
+ ( null , null ) => null ,
244
+ ( null , not null ) => _commonProperties == FrozenDictionary < string , string > . Empty ? null : new Dictionary < string , string > ( _commonProperties ) ,
245
+ ( not null , null ) => properties ,
246
+ ( not null , not null ) => Combine ( _commonProperties , properties ) ,
247
+ } ;
245
248
}
246
249
247
- private IDictionary < string , string > ? GetEventProperties ( IDictionary < string , string > ? properties )
250
+ static IDictionary < TKey , TValue > Combine < TKey , TValue > ( IDictionary < TKey , TValue > common , IDictionary < TKey , TValue > specific ) where TKey : notnull
248
251
{
249
- if ( properties is null )
252
+ IDictionary < TKey , TValue > eventMeasurements = new Dictionary < TKey , TValue > ( capacity : common . Count + specific . Count ) ;
253
+ foreach ( KeyValuePair < TKey , TValue > measurement in common )
250
254
{
251
- return _commonProperties ;
255
+ eventMeasurements [ measurement . Key ] = measurement . Value ;
252
256
}
253
- if ( _commonProperties == null )
257
+ foreach ( KeyValuePair < TKey , TValue > measurement in specific )
254
258
{
255
- return properties ;
259
+ eventMeasurements [ measurement . Key ] = measurement . Value ;
256
260
}
257
-
258
- var eventProperties = new Dictionary < string , string > ( _commonProperties ) ;
259
- if ( properties != null )
260
- {
261
- foreach ( KeyValuePair < string , string > property in properties )
262
- {
263
- eventProperties [ property . Key ] = property . Value ;
264
- }
261
+ return eventMeasurements ;
265
262
}
266
-
267
- return eventProperties ;
268
- }
269
263
}
0 commit comments