Merge pull request #40391 from ClickHouse/reduce-StringRef

Reduce some usage of StringRef
This commit is contained in:
Robert Schulze 2022-08-21 20:04:57 +02:00 committed by GitHub
commit 3aa5acdb35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 18 deletions

View File

@ -55,10 +55,9 @@ struct StringRef
bool empty() const { return size == 0; }
std::string toString() const { return std::string(data, size); }
explicit operator std::string() const { return toString(); }
std::string_view toView() const { return std::string_view(data, size); }
std::string_view toView() const { return std::string_view(data, size); }
constexpr explicit operator std::string_view() const { return std::string_view(data, size); }
};

View File

@ -813,8 +813,8 @@ struct JSONExtractTree
auto from_col = dictionary_type->createColumn();
if (impl->insertResultToColumn(*from_col, element))
{
StringRef value = from_col->getDataAt(0);
assert_cast<ColumnLowCardinality &>(dest).insertData(value.data, value.size);
std::string_view value = from_col->getDataAt(0).toView();
assert_cast<ColumnLowCardinality &>(dest).insertData(value.data(), value.size());
return true;
}
return false;

View File

@ -11,19 +11,19 @@ struct ExtractTopLevelDomain
static void execute(Pos data, size_t size, Pos & res_data, size_t & res_size)
{
StringRef host = StringRef(getURLHost(data, size));
std::string_view host = getURLHost(data, size);
res_data = data;
res_size = 0;
if (host.size != 0)
if (!host.empty())
{
if (host.data[host.size - 1] == '.')
host.size -= 1;
if (host[host.size() - 1] == '.')
host.remove_suffix(1);
const auto * host_end = host.data + host.size;
const auto * host_end = host.data() + host.size();
Pos last_dot = find_last_symbols_or_null<'.'>(host.data, host_end);
Pos last_dot = find_last_symbols_or_null<'.'>(host.data(), host_end);
if (!last_dot)
return;

View File

@ -129,11 +129,11 @@ public:
root_offsets_data.resize(input_rows_count);
for (size_t i = 0; i < input_rows_count; ++i)
{
StringRef current_row = column_haystack->getDataAt(i);
std::string_view current_row = column_haystack->getDataAt(i).toView();
// Extract all non-intersecting matches from haystack except group #0.
const auto * pos = current_row.data;
const auto * end = pos + current_row.size;
const auto * pos = current_row.data();
const auto * end = pos + current_row.size();
while (pos < end
&& regexp->Match({pos, static_cast<size_t>(end - pos)},
0, end - pos, regexp->UNANCHORED, matched_groups.data(), matched_groups.size()))

View File

@ -94,14 +94,14 @@ struct RepeatImpl
template <typename T>
static void constStrVectorRepeat(
const StringRef & copy_str,
std::string_view copy_str,
ColumnString::Chars & res_data,
ColumnString::Offsets & res_offsets,
const PaddedPODArray<T> & col_num)
{
UInt64 data_size = 0;
res_offsets.resize(col_num.size());
UInt64 str_size = copy_str.size;
UInt64 str_size = copy_str.size();
UInt64 col_size = col_num.size();
for (UInt64 i = 0; i < col_size; ++i)
{
@ -116,7 +116,7 @@ struct RepeatImpl
T repeat_time = col_num[i];
checkRepeatTime(repeat_time);
process(
reinterpret_cast<UInt8 *>(const_cast<char *>(copy_str.data)),
reinterpret_cast<UInt8 *>(const_cast<char *>(copy_str.data())),
res_data.data() + res_offsets[i - 1],
str_size + 1,
repeat_time);
@ -227,7 +227,7 @@ public:
{
/// Note that const-const case is handled by useDefaultImplementationForConstants.
StringRef copy_str = col_const->getDataColumn().getDataAt(0);
std::string_view copy_str = col_const->getDataColumn().getDataAt(0).toView();
if (castType(arguments[1].type.get(), [&](const auto & type)
{

View File

@ -766,7 +766,7 @@ void DistributedSink::writeToShard(const Block & block, const std::vector<std::s
/// Write the header.
const std::string_view header = header_buf.stringView();
writeVarUInt(DBMS_DISTRIBUTED_SIGNATURE_HEADER, out);
writeStringBinary(StringRef(header), out);
writeStringBinary(header, out);
writePODBinary(CityHash_v1_0_2::CityHash128(header.data(), header.size()), out);
stream.write(block);