| @@ -47,20 +47,48 @@ impl index::File { · 46 unmodified lines |
| 47 | reduce_progress.lock().unwrap().add_child(format!("thread {}", index)), // per thread progress | 47 | reduce_progress.lock().unwrap().add_child(format!("thread {}", index)), // per thread progress |
| 48 | ) | 48 | ) |
| 49 | }; | 49 | }; |
| | 50 | struct Chunks<I> { |
| | 51 | size: usize, |
| | 52 | iter: I, |
| | 53 | } |
| | 54 | impl<I> Iterator for Chunks<I> |
| | 55 | where |
| | 56 | I: Iterator<Item = pack::graph::Node>, |
| | 57 | { |
| | 58 | type Item = Vec<pack::graph::Node>; |
| | 59 | |
| | 60 | fn next(&mut self) -> Option<Self::Item> { |
| | 61 | let mut res = Vec::with_capacity(self.size); |
| | 62 | let mut items_left = self.size; |
| | 63 | while let Some(item) = self.iter.next() { |
| | 64 | res.push(item); |
| | 65 | items_left -= 1; |
| | 66 | if items_left == 0 { |
| | 67 | break; |
| | 68 | } |
| | 69 | } |
| | 70 | if res.is_empty() { |
| | 71 | None |
| | 72 | } else { |
| | 73 | Some(res) |
| | 74 | } |
| | 75 | } |
| | 76 | } |
| 50 | in_parallel_if( | 77 | in_parallel_if( |
| 51 | if_there_are_enough_objects, | 78 | if_there_are_enough_objects, |
| 52 | tree.bases(), | 79 | Chunks { |
| | 80 | size: 50, |
| | 81 | iter: tree.bases(), |
| | 82 | }, |
| 53 | thread_limit, | 83 | thread_limit, |
| 54 | state_per_thread, | 84 | state_per_thread, |
| 55 | |node: pack::graph::Node, | 85 | |input: Vec<pack::graph::Node>, |
| 56 | (buf, encode_buf, nodes, progress)| | 86 | (buf, encode_buf, nodes, progress)| |
| 57 | -> Result<Vec<pack::data::decode::Outcome>, Error> { | 87 | -> Result<Vec<pack::data::decode::Outcome>, Error> { |
| 58 | let mut stats = Vec::new(); | 88 | let mut stats = Vec::new(); |
| 59 | let mut header_buf = [0u8; 64]; | 89 | let mut header_buf = [0u8; 64]; |
| 60 | nodes.clear(); | | |
| 61 | nodes.push((node, 0)); | | |
| 62 | progress.init(None, Some("entries")); | | |
| 63 | let mut children = Vec::new(); | 90 | let mut children = Vec::new(); |
| | 91 | progress.init(None, Some("entries")); |
| 64 | | 92 | |
| 65 | struct CacheEntry { | 93 | struct CacheEntry { |
| 66 | kind: Kind, | 94 | kind: Kind, |
| @@ -92,33 +120,38 @@ impl index::File { · 25 unmodified lines |
| 92 | ) | 120 | ) |
| 93 | } | 121 | } |
| 94 | } | 122 | } |
| 95 | let mut cache = BTreeMap::new(); | | |
| 96 | | 123 | |
| 97 | while let Some((node, level)) = nodes.pop() { | 124 | for node in input { |
| 98 | let pack_offset = node.pack_offset; | 125 | nodes.clear(); |
| 99 | let index_entry = sorted_entries | 126 | nodes.push((node, 0)); |
| 100 | .binary_search_by(|e| e.pack_offset.cmp(&pack_offset)) | 127 | let mut cache = BTreeMap::new(); |
| 101 | .expect("tree created by our sorted entries"); | | |
| 102 | let index_entry_of_node = &sorted_entries[index_entry]; | | |
| 103 | | 128 | |
| 104 | tree.children(node, &mut children); | 129 | while let Some((node, level)) = nodes.pop() { |
| | 130 | let pack_offset = node.pack_offset; |
| | 131 | let index_entry = sorted_entries |
| | 132 | .binary_search_by(|e| e.pack_offset.cmp(&pack_offset)) |
| | 133 | .expect("tree created by our sorted entries"); |
| | 134 | let index_entry_of_node = &sorted_entries[index_entry]; |
| 105 | | 135 | |
| 106 | let shared_cache = &mut SharedCache(&mut cache); | 136 | tree.children(node, &mut children); |
| 107 | let mut stat = self.process_entry( | | |
| 108 | mode, | | |
| 109 | pack, | | |
| 110 | shared_cache, | | |
| 111 | buf, | | |
| 112 | encode_buf, | | |
| 113 | progress, | | |
| 114 | &mut header_buf, | | |
| 115 | index_entry_of_node, | | |
| 116 | )?; | | |
| 117 | stat.num_deltas = level; | | |
| 118 | stats.push(stat); | | |
| 119 | | 137 | |
| 120 | progress.inc(); | 138 | let shared_cache = &mut SharedCache(&mut cache); |
| 121 | nodes.extend(children.iter().cloned().map(|cn| (cn, level + 1))); | 139 | let mut stat = self.process_entry( |
| | 140 | mode, |
| | 141 | pack, |
| | 142 | shared_cache, |
| | 143 | buf, |
| | 144 | encode_buf, |
| | 145 | progress, |
| | 146 | &mut header_buf, |
| | 147 | index_entry_of_node, |
| | 148 | )?; |
| | 149 | stat.num_deltas = level; |
| | 150 | stats.push(stat); |
| | 151 | |
| | 152 | progress.inc(); |
| | 153 | nodes.extend(children.iter().cloned().map(|cn| (cn, level + 1))); |
| | 154 | } |
| 122 | } | 155 | } |
| 123 | | 156 | |
| 124 | Ok(stats) | 157 | Ok(stats) |