From 4caf2c4c338312df4a5ea1aea6ba1d55409bfa08 Mon Sep 17 00:00:00 2001 From: Robert Schulze Date: Sun, 21 Aug 2022 18:10:32 +0000 Subject: [PATCH] Reduce some usage of StringRef See #39535 and #39300 --- src/Columns/ColumnConst.h | 2 +- src/Columns/ColumnDecimal.h | 4 ++-- src/Columns/ColumnFixedString.h | 2 +- src/Columns/ColumnVector.h | 4 ++-- src/Columns/IColumn.h | 2 +- src/Common/ColumnsHashing.h | 6 +++--- src/Functions/reinterpretAs.cpp | 2 +- src/Interpreters/ExpressionJIT.cpp | 6 +++--- src/Interpreters/JIT/compileFunction.cpp | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Columns/ColumnConst.h b/src/Columns/ColumnConst.h index 21cfaf7f64c..b8b3984be20 100644 --- a/src/Columns/ColumnConst.h +++ b/src/Columns/ColumnConst.h @@ -269,7 +269,7 @@ public: bool isFixedAndContiguous() const override { return data->isFixedAndContiguous(); } bool valuesHaveFixedSize() const override { return data->valuesHaveFixedSize(); } size_t sizeOfValueIfFixed() const override { return data->sizeOfValueIfFixed(); } - StringRef getRawData() const override { return data->getRawData(); } + std::string_ref getRawData() const override { return data->getRawData(); } /// Not part of the common interface. diff --git a/src/Columns/ColumnDecimal.h b/src/Columns/ColumnDecimal.h index 03875121637..afae2cd641a 100644 --- a/src/Columns/ColumnDecimal.h +++ b/src/Columns/ColumnDecimal.h @@ -71,9 +71,9 @@ public: data.resize_assume_reserved(data.size() - n); } - StringRef getRawData() const override + std::string_view getRawData() const override { - return StringRef(reinterpret_cast(data.data()), byteSize()); + return {reinterpret_cast(data.data()), byteSize()}; } StringRef getDataAt(size_t n) const override diff --git a/src/Columns/ColumnFixedString.h b/src/Columns/ColumnFixedString.h index 711db056ee6..6d0b1910725 100644 --- a/src/Columns/ColumnFixedString.h +++ b/src/Columns/ColumnFixedString.h @@ -209,7 +209,7 @@ public: bool isFixedAndContiguous() const override { return true; } size_t sizeOfValueIfFixed() const override { return n; } - StringRef getRawData() const override { return StringRef(chars.data(), chars.size()); } + std::string_view getRawData() const override { return {chars.data(), chars.size()}; } /// Specialized part of interface, not from IColumn. void insertString(const String & string) { insertData(string.c_str(), string.size()); } diff --git a/src/Columns/ColumnVector.h b/src/Columns/ColumnVector.h index 6ba9abaca32..88e953891cc 100644 --- a/src/Columns/ColumnVector.h +++ b/src/Columns/ColumnVector.h @@ -332,9 +332,9 @@ public: bool isFixedAndContiguous() const override { return true; } size_t sizeOfValueIfFixed() const override { return sizeof(T); } - StringRef getRawData() const override + std::string_view getRawData() const override { - return StringRef(reinterpret_cast(data.data()), byteSize()); + return {reinterpret_cast(data.data()), byteSize()}; } StringRef getDataAt(size_t n) const override diff --git a/src/Columns/IColumn.h b/src/Columns/IColumn.h index 8b693015674..974925d247e 100644 --- a/src/Columns/IColumn.h +++ b/src/Columns/IColumn.h @@ -507,7 +507,7 @@ public: [[nodiscard]] virtual bool isFixedAndContiguous() const { return false; } /// If isFixedAndContiguous, returns the underlying data array, otherwise throws an exception. - [[nodiscard]] virtual StringRef getRawData() const { throw Exception("Column " + getName() + " is not a contiguous block of memory", ErrorCodes::NOT_IMPLEMENTED); } + [[nodiscard]] virtual std::string_view getRawData() const { throw Exception("Column " + getName() + " is not a contiguous block of memory", ErrorCodes::NOT_IMPLEMENTED); } /// If valuesHaveFixedSize, returns size of value, otherwise throw an exception. [[nodiscard]] virtual size_t sizeOfValueIfFixed() const { throw Exception("Values of column " + getName() + " are not fixed size.", ErrorCodes::CANNOT_GET_SIZE_OF_FIELD); } diff --git a/src/Common/ColumnsHashing.h b/src/Common/ColumnsHashing.h index 0e4617345fa..54446950567 100644 --- a/src/Common/ColumnsHashing.h +++ b/src/Common/ColumnsHashing.h @@ -41,12 +41,12 @@ struct HashMethodOneNumber /// If the keys of a fixed length then key_sizes contains their lengths, empty otherwise. HashMethodOneNumber(const ColumnRawPtrs & key_columns, const Sizes & /*key_sizes*/, const HashMethodContextPtr &) { - vec = key_columns[0]->getRawData().data; + vec = key_columns[0]->getRawData().data(); } explicit HashMethodOneNumber(const IColumn * column) { - vec = column->getRawData().data; + vec = column->getRawData().data(); } /// Creates context. Method is called once and result context is used in all threads. @@ -577,7 +577,7 @@ struct HashMethodKeysFixed columns_data.reset(new const char*[keys_size]); for (size_t i = 0; i < keys_size; ++i) - columns_data[i] = Base::getActualColumns()[i]->getRawData().data; + columns_data[i] = Base::getActualColumns()[i]->getRawData().data(); } #endif } diff --git a/src/Functions/reinterpretAs.cpp b/src/Functions/reinterpretAs.cpp index 8e656863cdb..76afedb4f06 100644 --- a/src/Functions/reinterpretAs.cpp +++ b/src/Functions/reinterpretAs.cpp @@ -301,7 +301,7 @@ private: ColumnFixedString::Chars & data_to = dst.getChars(); data_to.resize(n * rows); - memcpy(data_to.data(), src.getRawData().data, data_to.size()); + memcpy(data_to.data(), src.getRawData().data(), data_to.size()); } static void NO_INLINE executeToString(const IColumn & src, ColumnString & dst) diff --git a/src/Interpreters/ExpressionJIT.cpp b/src/Interpreters/ExpressionJIT.cpp index a179c4d8bf6..c37d4d5b6a2 100644 --- a/src/Interpreters/ExpressionJIT.cpp +++ b/src/Interpreters/ExpressionJIT.cpp @@ -113,14 +113,14 @@ public: const auto & null_map_column = nullable_column->getNullMapColumn(); auto nested_column_raw_data = nested_column.getRawData(); - __msan_unpoison(nested_column_raw_data.data, nested_column_raw_data.size); + __msan_unpoison(nested_column_raw_data.data(), nested_column_raw_data.size()); auto null_map_column_raw_data = null_map_column.getRawData(); - __msan_unpoison(null_map_column_raw_data.data, null_map_column_raw_data.size); + __msan_unpoison(null_map_column_raw_data.data(), null_map_column_raw_data.size()); } else { - __msan_unpoison(result_column->getRawData().data, result_column->getRawData().size); + __msan_unpoison(result_column->getRawData().data(), result_column->getRawData().size()); } #endif diff --git a/src/Interpreters/JIT/compileFunction.cpp b/src/Interpreters/JIT/compileFunction.cpp index 9d2ab40bf76..353ab84674c 100644 --- a/src/Interpreters/JIT/compileFunction.cpp +++ b/src/Interpreters/JIT/compileFunction.cpp @@ -47,11 +47,11 @@ ColumnData getColumnData(const IColumn * column) if (const auto * nullable = typeid_cast(column)) { - result.null_data = nullable->getNullMapColumn().getRawData().data; + result.null_data = nullable->getNullMapColumn().getRawData().data(); column = & nullable->getNestedColumn(); } - result.data = column->getRawData().data; + result.data = column->getRawData().data(); return result; }