From d331758f6db35418259eb0a332b81127c87002bd Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 13 Aug 2018 17:22:24 +0200 Subject: [PATCH] Add helper function to pop an element from a HashSet --- src/constant.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index b393c91f7fb..fd3d3d67c3f 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -150,16 +150,7 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a> ( ) { let memory = Memory::::new(tcx.at(DUMMY_SP), ()); - loop { - let alloc_id = { - if let Some(alloc_id) = cx.todo_allocs.iter().next().map(|alloc_id| *alloc_id) { - cx.todo_allocs.remove(&alloc_id); - alloc_id - } else { - break; - } - }; - + while let Some(alloc_id) = pop_set(&mut cx.todo_allocs) { let data_id = define_global_for_alloc_id(module, cx, alloc_id); println!("alloc_id {} data_id {}", alloc_id, data_id); if cx.done.contains(&data_id) { @@ -197,3 +188,12 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a> ( assert!(cx.todo_allocs.is_empty(), "{:?}", cx.todo_allocs); } + +fn pop_set(set: &mut HashSet) -> Option { + if let Some(elem) = set.iter().next().map(|elem| *elem) { + set.remove(&elem); + Some(elem) + } else { + None + } +} \ No newline at end of file