mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Inline size computations on Patch
.
This commit is contained in:
parent
7da058ca55
commit
3f81b9d8b9
@ -74,7 +74,14 @@ extension Patch {
|
||||
extension Patch {
|
||||
/// Returns a function which computes the size of a `patch` as the sum of the sizes of its terms, as computed by `size`.
|
||||
public static func sum(@noescape size: A throws -> Int)(_ patch: Patch) rethrows -> Int {
|
||||
return try (patch.state.before.map(size) ?? 0) + (patch.state.after.map(size) ?? 0)
|
||||
switch patch {
|
||||
case let .Replace(a, b):
|
||||
return try size(a) + size(b)
|
||||
case let .Insert(b):
|
||||
return try size(b)
|
||||
case let .Delete(a):
|
||||
return try size(a)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a function which computes the size of a `patch` as the absolute difference of the sizes of its terms, as computed by `size`.
|
||||
|
Loading…
Reference in New Issue
Block a user