From a828cde96dafe142642f0b09b2f9a45f71b91e23 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 2 May 2013 12:31:33 +0100 Subject: [PATCH] [btree] visitor now passed as a reference rather than shared_ptr --- persistent-data/data-structures/btree.h | 4 ++-- persistent-data/data-structures/btree.tcc | 18 +++++++++--------- persistent-data/space-maps/disk.cc | 6 +++--- thin-provisioning/device_checker.cc | 2 +- thin-provisioning/metadata_dumper.cc | 11 +++++------ unit-tests/btree_t.cc | 2 +- unit-tests/metadata_checker_t.cc | 4 ++-- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/persistent-data/data-structures/btree.h b/persistent-data/data-structures/btree.h index ac1b0d1..0e54d3f 100644 --- a/persistent-data/data-structures/btree.h +++ b/persistent-data/data-structures/btree.h @@ -334,7 +334,7 @@ namespace persistent_data { }; // Walks the tree in depth first order - void visit_depth_first(typename visitor::ptr visitor) const; + void visit_depth_first(visitor &visitor) const; private: template @@ -362,7 +362,7 @@ namespace persistent_data { uint64_t key, int *index); - void walk_tree(typename visitor::ptr visitor, + void walk_tree(visitor &visitor, btree_detail::node_location const &loc, block_address b) const; diff --git a/persistent-data/data-structures/btree.tcc b/persistent-data/data-structures/btree.tcc index 106775f..f64a90c 100644 --- a/persistent-data/data-structures/btree.tcc +++ b/persistent-data/data-structures/btree.tcc @@ -742,7 +742,7 @@ insert_location(btree_detail::shadow_spine &spine, template void -btree::visit_depth_first(typename visitor::ptr visitor) const +btree::visit_depth_first(visitor &v) const { node_location loc; @@ -751,13 +751,13 @@ btree::visit_depth_first(typename visitor::ptr visitor) con loc.sub_root = true; loc.key = boost::optional(); - walk_tree(visitor, loc, root_); - visitor->visit_complete(); + walk_tree(v, loc, root_); + v.visit_complete(); } template void -btree::walk_tree(typename visitor::ptr visitor, +btree::walk_tree(visitor &v, node_location const &loc, block_address b) const { @@ -766,7 +766,7 @@ btree::walk_tree(typename visitor::ptr visitor, read_ref blk = tm_->read_lock(b); internal_node o = to_node(blk); if (o.get_type() == INTERNAL) { - if (visitor->visit_internal(loc, o)) + if (v.visit_internal(loc, o)) for (unsigned i = 0; i < o.get_nr_entries(); i++) { node_location loc2(loc); @@ -774,11 +774,11 @@ btree::walk_tree(typename visitor::ptr visitor, loc2.sub_root = false; loc2.key = boost::optional(o.key_at(i)); - walk_tree(visitor, loc2, o.value_at(i)); + walk_tree(v, loc2, o.value_at(i)); } } else if (loc.level < Levels - 1) { - if (visitor->visit_internal_leaf(loc, o)) + if (v.visit_internal_leaf(loc, o)) for (unsigned i = 0; i < o.get_nr_entries(); i++) { node_location loc2(loc); @@ -787,12 +787,12 @@ btree::walk_tree(typename visitor::ptr visitor, loc2.sub_root = true; loc2.key = boost::optional(o.key_at(i)); - walk_tree(visitor, loc, o.value_at(i)); + walk_tree(v, loc, o.value_at(i)); } } else { leaf_node ov = to_node(blk); - visitor->visit_leaf(loc, ov); + v.visit_leaf(loc, ov); } } diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index 478f479..57b8baa 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -360,7 +360,7 @@ namespace { } virtual void check(block_counter &counter) const { - ref_count_checker::ptr v(new ref_count_checker(counter)); + ref_count_checker v(counter); ref_counts_.visit_depth_first(v); block_address nr_entries = div_up(get_nr_blocks(), ENTRIES_PER_BLOCK); @@ -584,9 +584,9 @@ namespace { } virtual void check(block_counter &counter, block_address nr_index_entries) const { - bitmap_tree_validator::ptr v(new bitmap_tree_validator(counter)); + bitmap_tree_validator v(counter); bitmaps_.visit_depth_first(v); - v->check_all_index_entries_present(nr_index_entries); + v.check_all_index_entries_present(nr_index_entries); } private: diff --git a/thin-provisioning/device_checker.cc b/thin-provisioning/device_checker.cc index a0dffbc..2f66693 100644 --- a/thin-provisioning/device_checker.cc +++ b/thin-provisioning/device_checker.cc @@ -75,7 +75,7 @@ damage_list_ptr device_checker::check() { block_counter counter; - device_visitor::ptr v(new device_visitor(counter)); + device_visitor v(counter); transaction_manager::ptr tm(open_core_tm(bm_)); detail_tree::ptr details(new detail_tree(tm, root_, device_details_traits::ref_counter())); diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 86043f4..c713eec 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -198,13 +198,12 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair) md->data_sm_->get_nr_blocks(), md_snap); - details_extractor::ptr de(new details_extractor); - + details_extractor de; md->details_->visit_depth_first(de); - if (de->corruption() && !repair) + if (de.corruption() && !repair) throw runtime_error("corruption in device details tree"); - map const &devs = de->get_devices(); + map const &devs = de.get_devices(); map::const_iterator it, end = devs.end(); for (it = devs.begin(); it != end; ++it) { @@ -217,10 +216,10 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair) dd.creation_time_, dd.snapshotted_time_); - mappings_extractor::ptr me(new mappings_extractor(dev_id, e, md->metadata_sm_, md->data_sm_)); + mappings_extractor me(dev_id, e, md->metadata_sm_, md->data_sm_); md->mappings_->visit_depth_first(me); - if (me->corruption() && !repair) { + if (me.corruption() && !repair) { ostringstream out; out << "corruption in mappings for device " << dev_id; throw runtime_error(out.str()); diff --git a/unit-tests/btree_t.cc b/unit-tests/btree_t.cc index 41a8e53..fb546e1 100644 --- a/unit-tests/btree_t.cc +++ b/unit-tests/btree_t.cc @@ -91,7 +91,7 @@ namespace { void check_constraints(btree<1, uint64_traits>::ptr tree) { typedef btree<1, uint64_traits> tree_type; - tree_type::visitor::ptr v(new constraint_visitor); + constraint_visitor v; tree->visit_depth_first(v); } } diff --git a/unit-tests/metadata_checker_t.cc b/unit-tests/metadata_checker_t.cc index 9f652c5..72a9c8c 100644 --- a/unit-tests/metadata_checker_t.cc +++ b/unit-tests/metadata_checker_t.cc @@ -355,12 +355,12 @@ TEST_F(DeviceCheckerTests, damaging_some_btree_nodes_results_in_the_correct_devi b.build(); - devices_visitor::ptr scanner(new devices_visitor); + devices_visitor scanner; transaction_manager::ptr tm = open_temporary_tm(bm_); detail_tree::ptr devices(new detail_tree(tm, devices_root(), device_details_traits::ref_counter())); devices->visit_depth_first(scanner); - devices_visitor::node_info n = scanner->random_node(); + devices_visitor::node_info n = scanner.random_node(); zero_block(n.b); damage_list_ptr damage = mk_checker()->check();