From 0f15a1b85ce5e605c441f5e01b4842f4bd2c99c2 Mon Sep 17 00:00:00 2001 From: Ronen Friedman Date: Mon, 14 Dec 2020 15:08:59 +0200 Subject: [PATCH] S3select: replacing a "naked loop" with std::copy_n ... and fixing some extra copying Signed-off-by: Ronen Friedman --- include/s3select_oper.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/include/s3select_oper.h b/include/s3select_oper.h index 41a5021d..d7fe49dc 100644 --- a/include/s3select_oper.h +++ b/include/s3select_oper.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -227,27 +228,17 @@ class scratch_area m_column_name_pos.push_back( std::pair(n, pos)); } - void update(std::vector& tokens, size_t num_of_tokens) + void update(const std::vector& tokens, size_t num_of_tokens) { - size_t i=0; - for(auto s : tokens) - { - if (i>=num_of_tokens) - { - break; - } - - m_columns[i++] = s; - } - m_upper_bound = i; - + std::copy_n(tokens.begin(), num_of_tokens, m_columns.begin()); + m_upper_bound = num_of_tokens; } int get_column_pos(const char* n) { //done only upon building the AST, not on "runtime" - for( auto iter : m_column_name_pos) + for (const auto& iter : m_column_name_pos) { if (!strcmp(iter.first.c_str(), n)) {