From d2720897c4b168157e734a08b64680d636d29cb9 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 5 Dec 2020 16:27:40 +0100 Subject: [PATCH] Some minor and small fixes --- src/query/command3.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/query/command3.h b/src/query/command3.h index 48cfc49..f719f4a 100644 --- a/src/query/command3.h +++ b/src/query/command3.h @@ -317,37 +317,45 @@ namespace ts { template > class command_builder_impl { public: - explicit command_builder_impl(std::string command, size_t expected_bulk_size = 128, size_t expected_bulks = 1) : _identifier{std::move(command)}, expected_bulk_size{expected_bulk_size} { + explicit command_builder_impl(std::string command, size_t expected_bulk_size = 128, size_t expected_bulks = 1) : identifier_{std::move(command)}, expected_bulk_size{expected_bulk_size} { for(size_t index = 0; index < expected_bulks; index++) - this->bulks.emplace_back(" ").reserve(expected_bulk_size); + this->bulks.emplace_back("").reserve(expected_bulk_size); } inline command_builder_impl> as_normalized() { - return command_builder_impl>{this->expected_bulk_size, this->_identifier, this->bulks.begin(), this->bulks.end()}; + return command_builder_impl>{this->expected_bulk_size, this->identifier_, this->bulks.begin(), this->bulks.end()}; } inline std::string build(bool with_empty = false) const { - if(this->builded.has_value() && !this->flag_changed) + if(this->builded.has_value() && !this->flag_changed) { return this->builded.value(); + } std::string result{}; - size_t required_size{this->_identifier.size()}; - for(auto& entry : this->bulks) + size_t required_size{this->identifier_.size()}; + for(auto& entry : this->bulks) { required_size += entry.size() + 1; + } + + result.append(this->identifier_); - result.append(this->_identifier); for(auto it = this->bulks.begin(); it != this->bulks.end(); it++) { - if(it->empty() && !with_empty) continue; + if(it->empty() && !with_empty) { + continue; + } result.append(*it, 0, it->length() - 1); - if(it + 1 != this->bulks.end()) + if(it + 1 != this->bulks.end()) { result.append("|"); + } } + if(!with_empty && !result.empty() && result.back() == '|') { this->builded = result.substr(0, result.length() - 1); } else { this->builded = result; } + this->flag_changed = false; return this->builded.value(); } @@ -398,10 +406,10 @@ namespace ts { bulk = " "; } private: - command_builder_impl(size_t expected, std::string identifier, typename vector_t::iterator begin, typename vector_t::iterator end) : expected_bulk_size{expected}, _identifier{std::move(identifier)}, bulks{begin, end} {} + command_builder_impl(size_t expected, std::string identifier, typename vector_t::iterator begin, typename vector_t::iterator end) : expected_bulk_size{expected}, identifier_{std::move(identifier)}, bulks{begin, end} {} const size_t expected_bulk_size; - const std::string _identifier; + const std::string identifier_; mutable bool flag_changed{false}; mutable std::optional builded{}; vector_t bulks{};