From ee43104209714e319b0b113c4a063b16c5d0f6a9 Mon Sep 17 00:00:00 2001 From: JackyWoo Date: Wed, 12 Jun 2024 11:48:46 +0800 Subject: [PATCH] Inline method push_back for compact string --- src/Common/CompactStrings.cpp | 15 +-------------- src/Common/CompactStrings.h | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Common/CompactStrings.cpp b/src/Common/CompactStrings.cpp index 1bf4b422b2..d625606fc8 100644 --- a/src/Common/CompactStrings.cpp +++ b/src/Common/CompactStrings.cpp @@ -1,6 +1,4 @@ -#include "CompactStrings.h" - -#include "Service/memcopy.h" +#include namespace RK @@ -24,17 +22,6 @@ void CompactStrings::reserve(size_t n, size_t total_size_) data.reserve(AVG_ELEMENT_SIZE_HINT * total_size_); } -void CompactStrings::push_back(const String & s) -{ - const size_t old_size = data.size(); - const size_t size_to_append = s.size(); - const size_t new_size = old_size + size_to_append; - - data.resize(new_size); - memcopy(data.data() + old_size, s.c_str(), size_to_append); - offsets.push_back(new_size); -} - StringRef CompactStrings::operator[](int64_t i) const { return StringRef(&data[offsets[i - 1]], offsets[i] - offsets[i - 1]); diff --git a/src/Common/CompactStrings.h b/src/Common/CompactStrings.h index ef88d46569..7935700dc0 100644 --- a/src/Common/CompactStrings.h +++ b/src/Common/CompactStrings.h @@ -1,7 +1,8 @@ #pragma once -#include "PODArray.h" -#include "common/StringRef.h" +#include +#include +#include namespace RK @@ -48,7 +49,17 @@ class CompactStrings void reserve(size_t n, size_t total_size = 0); - void push_back(const String & s); + inline void push_back(const String & s) + { + const size_t old_size = data.size(); + const size_t size_to_append = s.size(); + const size_t new_size = old_size + size_to_append; + + data.resize(new_size); + memcopy(data.data() + old_size, s.c_str(), size_to_append); + offsets.push_back(new_size); + } + template void push_back(Ttr begin, Ttr end) { for (Ttr it = begin; it != end; ++it)