Skip to content

Commit a4115ba

Browse files
Micah Kornfieldpitrou
authored andcommitted
ARROW-10074: [C++] Use string constructor instead of string_view.to_string
Closes apache#8250 from emkornfield/to_string Authored-by: Micah Kornfield <micahk@google.com> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 8eef4fd commit a4115ba

11 files changed

Lines changed: 18 additions & 17 deletions

File tree

cpp/src/arrow/dataset/discovery.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Result<std::shared_ptr<DatasetFactory>> FileSystemDatasetFactory::Make(
192192
return false;
193193
}
194194

195-
if (StartsWithAnyOf(relative->to_string(), options.selector_ignore_prefixes)) {
195+
if (StartsWithAnyOf(std::string(*relative), options.selector_ignore_prefixes)) {
196196
return true;
197197
}
198198

cpp/src/arrow/dataset/file_base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Status FileSystemDataset::Write(std::shared_ptr<Schema> schema,
208208
FragmentIterator fragment_it) {
209209
auto task_group = scan_context->TaskGroup();
210210

211-
base_dir = fs::internal::RemoveTrailingSlash(base_dir).to_string();
211+
base_dir = std::string(fs::internal::RemoveTrailingSlash(base_dir));
212212

213213
for (const auto& f : partitioning->schema()->fields()) {
214214
if (f->type()->id() == Type::DICTIONARY) {

cpp/src/arrow/dataset/file_csv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Result<std::unordered_set<std::string>> GetColumnNames(
6565
RETURN_NOT_OK(
6666
parser.VisitLastRow([&](const uint8_t* data, uint32_t size, bool quoted) -> Status {
6767
util::string_view view{reinterpret_cast<const char*>(data), size};
68-
if (column_names.emplace(view.to_string()).second) {
68+
if (column_names.emplace(std::string(view)).second) {
6969
return Status::OK();
7070
}
7171
return Status::Invalid("CSV file contained multiple columns named ", view);

cpp/src/arrow/dataset/filter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ struct DeserializeImpl {
14311431
switch (expression_type) {
14321432
case ExpressionType::FIELD: {
14331433
ARROW_ASSIGN_OR_RAISE(auto name, GetView<StringType>(struct_array, 0));
1434-
return field_ref(name.to_string());
1434+
return field_ref(std::string(name));
14351435
}
14361436

14371437
case ExpressionType::SCALAR: {

cpp/src/arrow/dataset/partition.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ std::shared_ptr<PartitioningFactory> HivePartitioning::MakeFactory(
543543

544544
std::string StripPrefixAndFilename(const std::string& path, const std::string& prefix) {
545545
auto maybe_base_less = fs::internal::RemoveAncestor(prefix, path);
546-
auto base_less = maybe_base_less ? maybe_base_less->to_string() : path;
546+
auto base_less = maybe_base_less ? std::string(*maybe_base_less) : path;
547547
auto basename_filename = fs::internal::GetAbstractPathParent(base_less);
548548
return basename_filename.first;
549549
}

cpp/src/arrow/filesystem/path_util.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::string GetAbstractPathExtension(const std::string& s) {
8080
// Empty extension
8181
return "";
8282
}
83-
return basename.substr(dot + 1).to_string();
83+
return std::string(basename.substr(dot + 1));
8484
}
8585

8686
Status ValidateAbstractPathParts(const std::vector<std::string>& parts) {
@@ -100,7 +100,7 @@ std::string ConcatAbstractPath(const std::string& base, const std::string& stem)
100100
if (base.empty()) {
101101
return stem;
102102
}
103-
return EnsureTrailingSlash(base) + RemoveLeadingSlash(stem).to_string();
103+
return EnsureTrailingSlash(base) + std::string(RemoveLeadingSlash(stem));
104104
}
105105

106106
std::string EnsureTrailingSlash(util::string_view v) {
@@ -186,7 +186,7 @@ std::vector<std::string> AncestorsFromBasePath(util::string_view base_path,
186186
util::string_view descendant) {
187187
std::vector<std::string> ancestry;
188188
if (auto relative = RemoveAncestor(base_path, descendant)) {
189-
auto relative_segments = fs::internal::SplitAbstractPath(relative->to_string());
189+
auto relative_segments = fs::internal::SplitAbstractPath(std::string(*relative));
190190

191191
// the last segment indicates descendant
192192
relative_segments.pop_back();
@@ -198,7 +198,7 @@ std::vector<std::string> AncestorsFromBasePath(util::string_view base_path,
198198

199199
for (auto&& relative_segment : relative_segments) {
200200
ancestry.push_back(JoinAbstractPath(
201-
std::vector<std::string>{base_path.to_string(), std::move(relative_segment)}));
201+
std::vector<std::string>{std::string(base_path), std::move(relative_segment)}));
202202
base_path = ancestry.back();
203203
}
204204
}

cpp/src/arrow/io/memory_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ TEST(TestBufferReader, Peek) {
203203
ASSERT_OK_AND_ASSIGN(view, reader.Peek(4));
204204

205205
ASSERT_EQ(4, view.size());
206-
ASSERT_EQ(data.substr(0, 4), view.to_string());
206+
ASSERT_EQ(data.substr(0, 4), std::string(view));
207207

208208
ASSERT_OK_AND_ASSIGN(view, reader.Peek(20));
209209
ASSERT_EQ(data.size(), view.size());
210-
ASSERT_EQ(data, view.to_string());
210+
ASSERT_EQ(data, std::string(view));
211211
}
212212

213213
TEST(TestBufferReader, ReadAsync) {

cpp/src/arrow/json/parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class RawArrayBuilder<Kind::kObject> {
372372
std::shared_ptr<Array> field_values;
373373
RETURN_NOT_OK(finish_child(field_builders_[i], &field_values));
374374
child_data[i] = field_values->data();
375-
fields[i] = field(field_names[i].to_string(), field_values->type(),
375+
fields[i] = field(std::string(field_names[i]), field_values->type(),
376376
field_builders_[i].nullable, Kind::Tag(field_builders_[i].kind));
377377
}
378378

cpp/src/arrow/scalar.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ struct ScalarParseImpl {
327327
return MakeScalar(std::move(type_), std::forward<Arg>(arg)).Value(&out_);
328328
}
329329

330-
Status FinishWithBuffer() { return Finish(Buffer::FromString(s_.to_string())); }
330+
Status FinishWithBuffer() { return Finish(Buffer::FromString(std::string(s_))); }
331331

332332
Result<std::shared_ptr<Scalar>> Finish() && {
333333
RETURN_NOT_OK(VisitTypeInline(*type_, this));
@@ -366,8 +366,9 @@ std::shared_ptr<Buffer> FormatToBuffer(Formatter&& formatter, const ScalarType&
366366
if (!from.is_valid) {
367367
return Buffer::FromString("null");
368368
}
369-
return formatter(
370-
from.value, [&](util::string_view v) { return Buffer::FromString(v.to_string()); });
369+
return formatter(from.value, [&](util::string_view v) {
370+
return Buffer::FromString(std::string(v));
371+
});
371372
}
372373

373374
// error fallback

cpp/src/arrow/scalar_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ TYPED_TEST(TestNumericScalar, Cast) {
567567
}
568568

569569
ASSERT_OK_AND_ASSIGN(auto cast_from_string,
570-
StringScalar(repr.to_string()).CastTo(type));
570+
StringScalar(std::string(repr)).CastTo(type));
571571
ASSERT_EQ(*cast_from_string, *scalar);
572572

573573
if (is_integer_type<TypeParam>::value) {

0 commit comments

Comments
 (0)