From a5e6b955708876ad76ae9f5973ce9bd7bdd35b0e Mon Sep 17 00:00:00 2001 From: William Ayd Date: Sun, 21 Jan 2024 22:34:11 -0500 Subject: [PATCH] More string_view less string (#234) --- pantab/src/pantab.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pantab/src/pantab.cpp b/pantab/src/pantab.cpp index 68ee83fd..3fcb522b 100644 --- a/pantab/src/pantab.cpp +++ b/pantab/src/pantab.cpp @@ -164,8 +164,13 @@ template class Utf8InsertHelper : public InsertHelper { const struct ArrowBufferView buffer_view = ArrowArrayViewGetBytesUnsafe(&array_view_, idx); +#if defined(_WIN32) && defined(_MSC_VER) const auto result = std::string{ buffer_view.data.as_char, static_cast(buffer_view.size_bytes)}; +#else + const auto result = std::string_view{ + buffer_view.data.as_char, static_cast(buffer_view.size_bytes)}; +#endif hyperapi::internal::ValueInserter{*inserter_}.addValue(result); } }; @@ -405,11 +410,13 @@ void write_to_hyper( for (int64_t i = 0; i < schema.n_children; i++) { const auto hypertype = hyperTypeFromArrowSchema(schema.children[i], &error); - const auto name = std::string{schema.children[i]->name}; // Almost all arrow types are nullable - hyper_columns.emplace_back(hyperapi::TableDefinition::Column{ - name, hypertype, hyperapi::Nullability::Nullable}); + const hyperapi::TableDefinition::Column column{ + std::string(schema.children[i]->name), hypertype, + hyperapi::Nullability::Nullable}; + + hyper_columns.emplace_back(std::move(column)); } const hyperapi::TableName table_name{hyper_schema, hyper_table}; @@ -546,9 +553,15 @@ class StringReadHelper : public ReadHelper { return; } +#if defined(_WIN32) && defined(_MSC_VER) const auto strval = value.get(); const ArrowStringView arrow_string_view{ strval.c_str(), static_cast(strval.size())}; +#else + const auto strval = value.get(); + const ArrowStringView arrow_string_view{ + strval.data(), static_cast(strval.size())}; +#endif if (ArrowArrayAppendString(array_, arrow_string_view)) { throw std::runtime_error("ArrowAppendString failed");