Skip to content

Commit

Permalink
Reduce string copying in array parsing.
Browse files Browse the repository at this point in the history
This should reduce the copying of strings in array parsing a bit.
Parsing an unquoted string is really just a matter of referring to the
input data, so we can use a `std::string_view` there instead of a
`std::string`.

Upon reflection I don't think this breaks the ABI, since it's purely an
internal call.  _Yes_ there's an externally visible symbol involved but
nobody has any business calling it.
  • Loading branch information
jtv committed Jul 20, 2024
1 parent 86f7d62 commit a736de9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/pqxx/array.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private:
template<pqxx::internal::encoding_group>
std::string::size_type scan_unquoted_string() const;
template<pqxx::internal::encoding_group>
std::string parse_unquoted_string(std::string::size_type end) const;
std::string_view parse_unquoted_string(std::string::size_type end) const;

template<pqxx::internal::encoding_group>
std::string::size_type scan_glyph(std::string::size_type pos) const;
Expand Down
3 changes: 1 addition & 2 deletions include/pqxx/internal/array-composite.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ scan_unquoted_string(char const input[], std::size_t size, std::size_t pos)
}


// XXX: Retire this. Just construct a string_view directly now!
/// Parse an unquoted array entry or cfield of a composite-type field.
template<pqxx::internal::encoding_group ENC>
inline std::string
inline std::string_view
parse_unquoted_string(char const input[], std::size_t end, std::size_t pos)
{
return {&input[pos], end - pos};
Expand Down
2 changes: 1 addition & 1 deletion src/array.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ std::string::size_type array_parser::scan_unquoted_string() const
* that happens to spell "NULL".
*/
template<pqxx::internal::encoding_group ENC>
std::string
std::string_view
array_parser::parse_unquoted_string(std::string::size_type end) const
{
return pqxx::internal::parse_unquoted_string<ENC>(
Expand Down

0 comments on commit a736de9

Please sign in to comment.