Skip to content

Commit

Permalink
Change Timer.record(duration: Duration) signature to avoid source bre…
Browse files Browse the repository at this point in the history
…akage (#144)
  • Loading branch information
hamzahrmalik authored May 15, 2024
1 parent eb18581 commit 0124d9a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions Sources/Metrics/Metrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ extension Timer {
///
/// - Parameters:
/// - duration: The `Duration` to record.
///
/// - Throws: `TimerError.durationToIntOverflow` if conversion from `Duration` to `Int64` of Nanoseconds overflowed.
@available(macOS 13, iOS 16, tvOS 15, watchOS 8, *)
@inlinable
public func record(_ duration: Duration) {
public func record(duration: Duration) {
// `Duration` doesn't have a nice way to convert it nanoseconds or seconds,
// and manual conversion can overflow.
let seconds = duration.components.seconds.multipliedReportingOverflow(by: 1_000_000_000)
Expand Down
4 changes: 2 additions & 2 deletions Tests/MetricsTests/MetricsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ class MetricsExtensionsTests: XCTestCase {

let duration = Duration(secondsComponent: 3, attosecondsComponent: 123_000_000_000_000_000)
let nanoseconds = duration.components.seconds * 1_000_000_000 + duration.components.attoseconds / 1_000_000_000
timer.record(duration)
timer.record(duration: duration)

// Record a Duration that would overflow,
// expect Int64.max to be recorded.
timer.record(Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))
timer.record(duration: Duration(secondsComponent: 10_000_000_000, attosecondsComponent: 123))

let testTimer = try metrics.expectTimer(timer)
XCTAssertEqual(testTimer.values.count, 2, "expected number of entries to match")
Expand Down

0 comments on commit 0124d9a

Please sign in to comment.