mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Manually fuse TermType.size
.
This commit is contained in:
parent
ab615dc84e
commit
7da058ca55
@ -30,18 +30,19 @@ extension TermType {
|
||||
///
|
||||
/// This is used to compute the cost of patches, such that a patch inserting a very large tree will be charged approximately the same as a very large tree consisting of many small patches.
|
||||
public var size: Int {
|
||||
return cata {
|
||||
switch $0 {
|
||||
func size(term: Self) -> Int {
|
||||
switch term.unwrap {
|
||||
case .Leaf:
|
||||
return 1
|
||||
case let .Indexed(i):
|
||||
return i.reduce(1, combine: +)
|
||||
case let .Fixed(i):
|
||||
return i.reduce(1, combine: +)
|
||||
case let .Keyed(k):
|
||||
return k.values.reduce(1, combine: +)
|
||||
case let .Indexed(a):
|
||||
return a.reduce(0) { $0 + size($1) }
|
||||
case let .Fixed(a):
|
||||
return a.reduce(0) { $0 + size($1) }
|
||||
case let .Keyed(a):
|
||||
return a.reduce(0) { $0 + size($1.1) }
|
||||
}
|
||||
}
|
||||
return size(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user