From 69c3533d97ae8e74ea1d70c4f787d42bf736bf3c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 12 Oct 2020 14:22:44 +0300 Subject: [PATCH 1/3] sstables: deinline bound_kind_m formatter The formatter is by no means hot code and should not be inlined. --- sstables/m_format_read_helpers.cc | 32 +++++++++++++++++++++++++++++++ sstables/m_format_read_helpers.hh | 32 +------------------------------ 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/sstables/m_format_read_helpers.cc b/sstables/m_format_read_helpers.cc index 7a9f2981bc..67bace6b6a 100644 --- a/sstables/m_format_read_helpers.cc +++ b/sstables/m_format_read_helpers.cc @@ -59,3 +59,35 @@ future read_signed_vint(random_access_reader& in) { } } // namespace sstables + +std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind) { + switch (kind) { + case sstables::bound_kind_m::excl_end: + out << "excl_end"; + break; + case sstables::bound_kind_m::incl_start: + out << "incl_start"; + break; + case sstables::bound_kind_m::excl_end_incl_start: + out << "excl_end_incl_start"; + break; + case sstables::bound_kind_m::static_clustering: + out << "static_clustering"; + break; + case sstables::bound_kind_m::clustering: + out << "clustering"; + break; + case sstables::bound_kind_m::incl_end_excl_start: + out << "incl_end_excl_start"; + break; + case sstables::bound_kind_m::incl_end: + out << "incl_end"; + break; + case sstables::bound_kind_m::excl_start: + out << "excl_start"; + break; + default: + out << static_cast(kind); + } + return out; +} diff --git a/sstables/m_format_read_helpers.hh b/sstables/m_format_read_helpers.hh index 674a17ec3e..93004e27bc 100644 --- a/sstables/m_format_read_helpers.hh +++ b/sstables/m_format_read_helpers.hh @@ -99,34 +99,4 @@ inline gc_clock::time_point parse_expiry(const serialization_header& header, }; // namespace sstables -inline std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind) { - switch (kind) { - case sstables::bound_kind_m::excl_end: - out << "excl_end"; - break; - case sstables::bound_kind_m::incl_start: - out << "incl_start"; - break; - case sstables::bound_kind_m::excl_end_incl_start: - out << "excl_end_incl_start"; - break; - case sstables::bound_kind_m::static_clustering: - out << "static_clustering"; - break; - case sstables::bound_kind_m::clustering: - out << "clustering"; - break; - case sstables::bound_kind_m::incl_end_excl_start: - out << "incl_end_excl_start"; - break; - case sstables::bound_kind_m::incl_end: - out << "incl_end"; - break; - case sstables::bound_kind_m::excl_start: - out << "excl_start"; - break; - default: - out << static_cast(kind); - } - return out; -} +std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind); From a00fca1a693360fb12df96fe8e19c654194bd87c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 12 Oct 2020 18:47:03 +0300 Subject: [PATCH 2/3] sstables: move bound_kind_m formatter to its natural place Move bound_kind_m's formatter to the same header file where is is defined. This prevents cases where the compiler decays the type (an enum) to the underlying integral type because it does not see the formatter declaration, resulting in the wrong output. --- sstables/m_format_read_helpers.hh | 2 -- sstables/mx/types.hh | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sstables/m_format_read_helpers.hh b/sstables/m_format_read_helpers.hh index 93004e27bc..efddca3cc3 100644 --- a/sstables/m_format_read_helpers.hh +++ b/sstables/m_format_read_helpers.hh @@ -98,5 +98,3 @@ inline gc_clock::time_point parse_expiry(const serialization_header& header, } }; // namespace sstables - -std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind); diff --git a/sstables/mx/types.hh b/sstables/mx/types.hh index f419d18481..6dae347c8a 100644 --- a/sstables/mx/types.hh +++ b/sstables/mx/types.hh @@ -22,6 +22,7 @@ #pragma once #include "clustering_bounds_comparator.hh" +#include namespace sstables { @@ -95,3 +96,5 @@ inline bound_kind boundary_to_end_bound(bound_kind_m kind) { } } + +std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind); From 5065ae835f3ec8e7831abd6cb036434b7f68e3d5 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 12 Oct 2020 19:53:24 +0300 Subject: [PATCH 3/3] sstables: move bound_kind_m formatter to namespace sstables Without this, clang complains that we violate argument dependent lookup rules: note: 'operator<<' should be declared prior to the call site or in namespace 'sstables' std::ostream& operator<<(std::ostream&, const sstables::bound_kind_m&); we can't enforce the #include order, but we can easily move it it to namespace sstables (where it belongs anyway), so let's do that. gcc is happy either way. --- sstables/m_format_read_helpers.cc | 4 ++-- sstables/mx/types.hh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sstables/m_format_read_helpers.cc b/sstables/m_format_read_helpers.cc index 67bace6b6a..6d4d8ed7de 100644 --- a/sstables/m_format_read_helpers.cc +++ b/sstables/m_format_read_helpers.cc @@ -58,8 +58,6 @@ future read_signed_vint(random_access_reader& in) { return read_vint_impl(in); } -} // namespace sstables - std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind) { switch (kind) { case sstables::bound_kind_m::excl_end: @@ -91,3 +89,5 @@ std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind) { } return out; } + +} // namespace sstables diff --git a/sstables/mx/types.hh b/sstables/mx/types.hh index 6dae347c8a..91c59b6885 100644 --- a/sstables/mx/types.hh +++ b/sstables/mx/types.hh @@ -95,6 +95,6 @@ inline bound_kind boundary_to_end_bound(bound_kind_m kind) { return (kind == bound_kind_m::incl_end_excl_start) ? bound_kind::incl_end : bound_kind::excl_end; } -} - std::ostream& operator<<(std::ostream& out, sstables::bound_kind_m kind); + +}