From 62d09c675226d891fdf4a69016de7fb6fec3959b Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Tue, 12 Jan 2021 18:09:00 +0800 Subject: [PATCH] [thin_debug] Reduce code size by eliminating duplicated types This patch doesn't have a significant effect - only a few KBs of code is reduced. However, it's still a nice have. --- thin-provisioning/thin_debug.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/thin-provisioning/thin_debug.cc b/thin-provisioning/thin_debug.cc index bee3548..8a175e0 100644 --- a/thin-provisioning/thin_debug.cc +++ b/thin-provisioning/thin_debug.cc @@ -215,6 +215,8 @@ namespace { class device_details_show_traits : public thin_provisioning::device_tree_detail::device_details_traits { public: + typedef thin_provisioning::device_tree_detail::device_details_traits value_trait; + static void show(formatter &f, string const &key, thin_provisioning::device_tree_detail::device_details const &value) { field(f, "mapped blocks", value.mapped_blocks_); @@ -226,6 +228,8 @@ namespace { class uint64_show_traits : public uint64_traits { public: + typedef uint64_traits value_trait; + static void show(formatter &f, string const &key, uint64_t const &value) { field(f, key, lexical_cast(value)); } @@ -233,6 +237,8 @@ namespace { class block_show_traits : public thin_provisioning::mapping_tree_detail::block_traits { public: + typedef thin_provisioning::mapping_tree_detail::block_traits value_trait; + static void show(formatter &f, string const &key, thin_provisioning::mapping_tree_detail::block_time const &value) { field(f, "block", value.block_); @@ -240,7 +246,7 @@ namespace { } }; - template + template class show_btree_node : public command { public: explicit show_btree_node(metadata::ptr md) @@ -256,18 +262,18 @@ namespace { block_address block = lexical_cast(args[1]); block_manager::read_ref rr = md_->tm_->read_lock(block); - node_ref n = btree_detail::to_node(rr); + node_ref n = btree_detail::to_node(rr); if (n.get_type() == INTERNAL) show_node(n, out); else { - node_ref n = btree_detail::to_node(rr); - show_node(n, out); + node_ref n = btree_detail::to_node(rr); + show_node(n, out); } } private: - template - void show_node(node_ref n, ostream &out) { + template + void show_node(node_ref n, ostream &out) { xml_formatter f; field(f, "csum", n.get_checksum()); @@ -280,7 +286,7 @@ namespace { for (unsigned i = 0; i < n.get_nr_entries(); i++) { formatter::ptr f2(new xml_formatter); field(*f2, "key", n.key_at(i)); - VT::show(*f2, "value", n.value_at(i)); + ST::show(*f2, "value", n.value_at(i)); f.child("child", f2); }