@@ -323,8 +323,6 @@ private struct StringCodingKey: CodingKey {
323
323
}
324
324
}
325
325
326
-
327
-
328
326
/// Helper for dimensions
329
327
public struct DimensionLabels : MetricLabels {
330
328
let dimensions : [ ( String , String ) ]
@@ -339,21 +337,24 @@ public struct DimensionLabels: MetricLabels {
339
337
340
338
public func encode( to encoder: Encoder ) throws {
341
339
var container = encoder. container ( keyedBy: StringCodingKey . self)
342
- try self . dimensions. forEach {
343
- try container. encode ( $0 . 1 , forKey: . init( $0 . 0 ) )
340
+ for (key , value ) in self . dimensions {
341
+ try container. encode ( value , forKey: . init( key ) )
344
342
}
345
343
}
346
344
347
345
public func hash( into hasher: inout Hasher ) {
348
- hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
349
- }
350
-
351
- fileprivate var identifiers : String {
352
- return dimensions. map { $0. 0 } . joined ( separator: " - " )
346
+ for (key, value) in dimensions {
347
+ hasher. combine ( key)
348
+ hasher. combine ( value)
349
+ }
353
350
}
354
-
351
+
355
352
public static func == ( lhs: DimensionLabels , rhs: DimensionLabels ) -> Bool {
356
- return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " }
353
+ guard lhs. dimensions. count == rhs. dimensions. count else { return false }
354
+ for index in 0 ..< lhs. dimensions. count {
355
+ guard lhs. dimensions [ index] == rhs. dimensions [ index] else { return false }
356
+ }
357
+ return false
357
358
}
358
359
}
359
360
@@ -364,79 +365,53 @@ public struct DimensionHistogramLabels: HistogramLabels {
364
365
/// Bucket
365
366
public var le : String
366
367
/// Dimensions
367
- let dimensions : [ ( String , String ) ]
368
+ let labels : DimensionLabels
368
369
369
370
/// Empty init
370
371
public init ( ) {
371
372
self . le = " "
372
- self . dimensions = [ ]
373
+ self . labels = DimensionLabels ( )
373
374
}
374
375
375
376
/// Init with dimensions
376
377
public init ( _ dimensions: [ ( String , String ) ] ) {
377
378
self . le = " "
378
- self . dimensions = dimensions
379
+ self . labels = DimensionLabels ( dimensions)
379
380
}
380
381
381
382
public func encode( to encoder: Encoder ) throws {
382
383
var container = encoder. container ( keyedBy: StringCodingKey . self)
383
- try self . dimensions . forEach {
384
- try container. encode ( $0 . 1 , forKey: . init( $0 . 0 ) )
384
+ for (key , value ) in self . labels . dimensions {
385
+ try container. encode ( value , forKey: . init( key ) )
385
386
}
386
387
try container. encode ( le, forKey: . init( " le " ) )
387
388
}
388
-
389
- public func hash( into hasher: inout Hasher ) {
390
- hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
391
- hasher. combine ( le)
392
- }
393
-
394
- fileprivate var identifiers : String {
395
- return dimensions. map { $0. 0 } . joined ( separator: " - " )
396
- }
397
-
398
- public static func == ( lhs: DimensionHistogramLabels , rhs: DimensionHistogramLabels ) -> Bool {
399
- return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } && rhs. le == lhs. le
400
- }
401
389
}
402
390
403
391
/// Helper for dimensions
404
392
public struct DimensionSummaryLabels : SummaryLabels {
405
393
/// Quantile
406
394
public var quantile : String
407
395
/// Dimensions
408
- let dimensions : [ ( String , String ) ]
409
-
396
+ let labels : DimensionLabels
397
+
410
398
/// Empty init
411
399
public init ( ) {
412
400
self . quantile = " "
413
- self . dimensions = [ ]
401
+ self . labels = DimensionLabels ( )
414
402
}
415
403
416
404
/// Init with dimensions
417
405
public init ( _ dimensions: [ ( String , String ) ] ) {
418
406
self . quantile = " "
419
- self . dimensions = dimensions
407
+ self . labels = DimensionLabels ( dimensions)
420
408
}
421
409
422
410
public func encode( to encoder: Encoder ) throws {
423
411
var container = encoder. container ( keyedBy: StringCodingKey . self)
424
- try self . dimensions . forEach {
425
- try container. encode ( $0 . 1 , forKey: . init( $0 . 0 ) )
412
+ for (key , value ) in self . labels . dimensions {
413
+ try container. encode ( value , forKey: . init( key ) )
426
414
}
427
415
try container. encode ( quantile, forKey: . init( " quantile " ) )
428
416
}
429
-
430
- public func hash( into hasher: inout Hasher ) {
431
- hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
432
- hasher. combine ( quantile)
433
- }
434
-
435
- fileprivate var identifiers : String {
436
- return dimensions. map { $0. 0 } . joined ( separator: " - " )
437
- }
438
-
439
- public static func == ( lhs: DimensionSummaryLabels , rhs: DimensionSummaryLabels ) -> Bool {
440
- return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } && rhs. quantile == lhs. quantile
441
- }
442
417
}
0 commit comments