aboutsummaryrefslogtreecommitdiff
path: root/src/tree
diff options
context:
space:
mode:
Diffstat (limited to 'src/tree')
-rw-r--r--src/tree/file_builder.rs10
-rw-r--r--src/tree/mod.rs16
2 files changed, 20 insertions, 6 deletions
diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs
index c977b254c..430303ce9 100644
--- a/src/tree/file_builder.rs
+++ b/src/tree/file_builder.rs
@@ -81,7 +81,7 @@ impl FileBuilder {
81 } 81 }
82 82
83 fn add_len(&mut self, child: NodeIdx) { 83 fn add_len(&mut self, child: NodeIdx) {
84 let range = self.nodes[child.0 as usize].range; 84 let range = self.nodes[child].range;
85 grow(&mut self.current_parent().range, range); 85 grow(&mut self.current_parent().range, range);
86 } 86 }
87 87
@@ -90,13 +90,13 @@ impl FileBuilder {
90 } 90 }
91 91
92 fn current_parent(&mut self) -> &mut NodeData { 92 fn current_parent(&mut self) -> &mut NodeData {
93 let NodeIdx(idx) = self.current_id(); 93 let idx = self.current_id();
94 &mut self.nodes[idx as usize] 94 &mut self.nodes[idx]
95 } 95 }
96 96
97 fn current_sibling(&mut self) -> Option<&mut NodeData> { 97 fn current_sibling(&mut self) -> Option<&mut NodeData> {
98 let NodeIdx(idx) = self.in_progress.last().unwrap().1?; 98 let idx = self.in_progress.last().unwrap().1?;
99 Some(&mut self.nodes[idx as usize]) 99 Some(&mut self.nodes[idx])
100 } 100 }
101} 101}
102 102
diff --git a/src/tree/mod.rs b/src/tree/mod.rs
index b90a5d7d3..7c4162a68 100644
--- a/src/tree/mod.rs
+++ b/src/tree/mod.rs
@@ -70,7 +70,7 @@ impl<'f> Node<'f> {
70 } 70 }
71 71
72 fn data(&self) -> &'f NodeData { 72 fn data(&self) -> &'f NodeData {
73 &self.file.nodes[self.idx.0 as usize] 73 &self.file.nodes[self.idx]
74 } 74 }
75 75
76 fn as_node(&self, idx: Option<NodeIdx>) -> Option<Node<'f>> { 76 fn as_node(&self, idx: Option<NodeIdx>) -> Option<Node<'f>> {
@@ -102,3 +102,17 @@ struct NodeData {
102 first_child: Option<NodeIdx>, 102 first_child: Option<NodeIdx>,
103 next_sibling: Option<NodeIdx>, 103 next_sibling: Option<NodeIdx>,
104} 104}
105
106impl ::std::ops::Index<NodeIdx> for Vec<NodeData> {
107 type Output = NodeData;
108
109 fn index(&self, NodeIdx(idx): NodeIdx) -> &NodeData {
110 &self[idx as usize]
111 }
112}
113
114impl ::std::ops::IndexMut<NodeIdx> for Vec<NodeData> {
115 fn index_mut(&mut self, NodeIdx(idx): NodeIdx) -> &mut NodeData {
116 &mut self[idx as usize]
117 }
118} \ No newline at end of file