From 7a6729159f359da8def1e07811323f5818482e1e Mon Sep 17 00:00:00 2001 From: Wojciech Mitros Date: Tue, 6 Jul 2021 15:46:45 +0200 Subject: [PATCH] kl sstable reader: replace switch with standard flow control We get rid of the switch by using the infinite loop around the switch for jumping to the first case, adding an infinite loop around the second case (one break from the switch with the state of the first case becomes a break of the new while), and adding an if around the first case (because we never break in the first case). --- sstables/kl/reader_impl.hh | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/sstables/kl/reader_impl.hh b/sstables/kl/reader_impl.hh index accd40351d..54704ccb85 100644 --- a/sstables/kl/reader_impl.hh +++ b/sstables/kl/reader_impl.hh @@ -215,8 +215,7 @@ public: private: processing_result_generator do_process_state() { while (true) { - switch (_state) { - case state::ROW_START: + if (_state == state::ROW_START) { if (read_short_length_bytes(*_processing_data, _key) != read_status::ready) { _state = state::DELETION_TIME; co_yield row_consumer::proceed::yes; @@ -243,7 +242,8 @@ private: co_yield row_consumer::proceed::no; } } - case state::ATOM_START: + } + while (true) { if (read_short_length_bytes(*_processing_data, _key) != read_status::ready) { _state = state::ATOM_START_2; co_yield row_consumer::proceed::yes; @@ -251,11 +251,7 @@ private: if (_u16 == 0) { // end of row marker _state = state::ROW_START; - if (_consumer.consume_row_end() == - row_consumer::proceed::no) { - co_yield row_consumer::proceed::no; - continue; - } + co_yield _consumer.consume_row_end(); break; } else { _state = state::ATOM_MASK; @@ -294,11 +290,8 @@ private: _key.release(); _val.release(); _state = state::ATOM_START; - if (ret == row_consumer::proceed::no) { - co_yield row_consumer::proceed::no; - continue; - } - break; + co_yield ret; + continue; } } else if ((mask & column_mask::counter) != column_mask::none) { _deleted = false; @@ -377,13 +370,8 @@ private: _val_fragmented.remove_prefix(_val_fragmented.size_bytes()); _state = state::ATOM_START; co_yield ret; - continue; } - default: - __builtin_unreachable(); } - - co_yield row_consumer::proceed::yes; } } public: