Skip to content

Commit

Permalink
Optimize csv_encoder for streaming case
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 27, 2025
1 parent 9bfe04e commit 0d47999
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions include/jsoncons_ext/csv/csv_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,11 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
{
for (const auto& item : column_names_)
{
string_type str{alloc_};
str.push_back('/');
str.append(item.data(), item.size());
column_paths_.emplace_back(str);
column_path_value_map_.emplace(str, string_type{alloc_});
column_path_name_map_.emplace(std::move(str), item);
jpointer_type col_path;
col_path.append(item);
column_paths_.emplace_back(col_path);
column_path_value_map_.emplace(col_path, string_type{alloc_});
column_path_name_map_.emplace(std::move(col_path), item);
}
has_column_mapping_ = true;
}
Expand All @@ -291,12 +290,11 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
{
for (const auto& item : column_names_)
{
string_type str{alloc_};
str.push_back('/');
str.append(item.data(), item.size());
column_paths_.emplace_back(str);
column_path_value_map_.emplace(str, string_type{alloc_});
column_path_name_map_.emplace(std::move(str), item);
jpointer_type col_path;
col_path.append(item);
column_paths_.emplace_back(col_path);
column_path_value_map_.emplace(col_path, string_type{alloc_});
column_path_name_map_.emplace(std::move(col_path), item);
}
has_column_mapping_ = true;
}
Expand Down Expand Up @@ -515,14 +513,13 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
std::size_t index = 0;
for (const auto& item : column_names_)
{
string_type str{alloc_};
str.push_back('/');
jpointer_type col_path;
buffer_.clear();
jsoncons::detail::from_integer(index, buffer_);
str.append(buffer_.data(), buffer_.size());
column_paths_.emplace_back(str);
column_path_value_map_.emplace(str, string_type{alloc_});
column_path_name_map_.emplace(std::move(str), item);
col_path.append(buffer_);
column_paths_.emplace_back(col_path);
column_path_value_map_.emplace(col_path, string_type{alloc_});
column_path_name_map_.emplace(std::move(col_path), item);
++index;
}
has_column_mapping_ = true;
Expand Down

0 comments on commit 0d47999

Please sign in to comment.