Skip to content

Commit 1b1ee87

Browse files
committed
Inlining clamps
They're very simple; there should be no cost to this
1 parent e8ac315 commit 1b1ee87

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Sources/BasicMathTools/Clamps.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Foundation
1717
/// - max: The highest possible returned value
1818
///
1919
/// - Returns: `value`, clamped to be between `min` (inclusive) and `max` (inclusive)
20+
@inline(__always)
2021
public func clamp <Value: Comparable> (min: Value, value: Value, max: Value) -> Value {
2122
Swift.max(min, Swift.min(value, max))
2223
}
@@ -32,6 +33,7 @@ public extension Comparable {
3233
/// - max: The highest possible returned value
3334
///
3435
/// - Returns: this value, clamped to be between `min` (inclusive) and `max` (inclusive)
36+
@inline(__always)
3537
func clamped(min: Self, max: Self) -> Self {
3638
clamp(min: min, value: self, max: max)
3739
}
@@ -42,6 +44,7 @@ public extension Comparable {
4244
/// - Parameter range: The range of possible values to be returned
4345
///
4446
/// - Returns: this value, clamped to be between `range.lowerBound` (inclusive) and `range.upperBound` (inclusive)
47+
@inline(__always)
4548
func clamped(within range: ClosedRange<Self>) -> Self {
4649
clamped(min: range.lowerBound, max: range.upperBound)
4750
}

0 commit comments

Comments
 (0)