Skip to content

Commit

Permalink
Use mem::take to save on memory allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
InnovativeInventor committed May 17, 2022
1 parent cd7cecc commit 46d0950
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
use std::mem;

use std::cmp::Ordering;
use std::collections::VecDeque;
Expand Down Expand Up @@ -209,8 +211,10 @@ pub fn balanced_cut_edge(
// this will be false if root
let neighbor = unseen_neighbors[0];
pops[neighbor.index()] += pop.clone();
let mut current_partition_tracker = same_partition_tracker[node.index()].clone();
// let mut current_partition_tracker = same_partition_tracker[node.index()].clone();
let mut current_partition_tracker = mem::take(&mut same_partition_tracker[node.index()]);
same_partition_tracker[neighbor.index()].append(&mut current_partition_tracker);
// same_partition_tracker[neighbor.index()].append(&mut current_partition_tracker);
// eprintln!("node pushed to queue (pop = {}, target = {}): {}", pops[neighbor.index()], pop_target, neighbor.index());

if !node_queue.contains(&neighbor) {
Expand Down Expand Up @@ -270,7 +274,7 @@ pub fn bipartition_tree(
let mut balanced_nodes: Vec<(usize, Vec<usize>)> = vec![];

while balanced_nodes.len() == 0 {
// Wee: https://pyo3.rs/v0.15.1/memory.html#gil-bound-memory
// See: https://pyo3.rs/v0.15.1/memory.html#gil-bound-memory
// (workaround to force objects to be gc'ed on each loop)
let pool = unsafe { py.new_pool() };
let py = pool.python();
Expand Down

0 comments on commit 46d0950

Please sign in to comment.