1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +03:00

Compute the count eagerly.

This commit is contained in:
Rob Rix 2015-10-28 18:22:53 -04:00
parent 8d4bc19dc1
commit e2e37a011d

View File

@ -14,17 +14,17 @@ extension TSNode {
} }
var children: AnyRandomAccessCollection<TSNode> { var children: AnyRandomAccessCollection<TSNode> {
return AnyRandomAccessCollection(ChildrenCollection(node: self, count: ts_node_child_count, child: ts_node_child)) return AnyRandomAccessCollection(ChildrenCollection(node: self, count: ts_node_child_count(self), child: ts_node_child))
} }
var namedChildren: AnyRandomAccessCollection<TSNode> { var namedChildren: AnyRandomAccessCollection<TSNode> {
return AnyRandomAccessCollection(ChildrenCollection(node: self, count: ts_node_named_child_count, child: ts_node_named_child)) return AnyRandomAccessCollection(ChildrenCollection(node: self, count: ts_node_named_child_count(self), child: ts_node_named_child))
} }
private struct ChildrenCollection: CollectionType { private struct ChildrenCollection: CollectionType {
let node: TSNode let node: TSNode
let count: TSNode -> Int let count: Int
let child: (TSNode, Int) -> TSNode let child: (TSNode, Int) -> TSNode
subscript (index: Int) -> TSNode { subscript (index: Int) -> TSNode {
@ -33,7 +33,7 @@ extension TSNode {
let startIndex = 0 let startIndex = 0
var endIndex: Int { var endIndex: Int {
return count(node) return count
} }
} }
} }