-
Notifications
You must be signed in to change notification settings - Fork 180
Improved support for string_views for TOML and XML #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,7 @@ | |
| #include "Parser.hpp" | ||
| #include "Reader.hpp" | ||
|
|
||
| namespace rfl { | ||
| namespace xml { | ||
| namespace rfl ::xml { | ||
|
|
||
| using InputVarType = typename Reader::InputVarType; | ||
|
|
||
|
|
@@ -32,7 +31,7 @@ auto read(const InputVarType& _var) { | |
| template <class T, class... Ps> | ||
| Result<T> read(const std::string_view _xml_str) { | ||
| pugi::xml_document doc; | ||
| const auto result = doc.load_string(_xml_str.data()); | ||
| const auto result = doc.load_buffer(_xml_str.data(), _xml_str.size()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent change switching from Using
|
||
| if (!result) { | ||
| return error("XML string could not be parsed: " + | ||
| std::string(result.description())); | ||
|
|
@@ -49,7 +48,6 @@ auto read(std::istream& _stream) { | |
| return read<T, Ps...>(xml_str); | ||
| } | ||
|
|
||
| } // namespace xml | ||
| } // namespace rfl | ||
| } // namespace rfl::xml | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,7 +142,7 @@ | |
| "dependencies": [ | ||
| { | ||
| "name": "pugixml", | ||
| "version>=": "1.14" | ||
| "version>=": "1.15" | ||
| } | ||
| ] | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change to directly use
::toml::parse(_toml_str)withstd::string_view(and subsequently removing thestd::stringoverload that convertedstd::string_viewtostd::string) is a good efficiency improvement.Previously, a
std::string_viewmight be converted to astd::stringbefore parsing (as seen in the removed overloadreturn read<T, Ps...>(std::string(_toml_str));), which involved an unnecessary allocation and copy.By parsing the
std::string_viewdirectly usingtoml::parse(which supportsstd::string_view), this overhead is avoided. This is a valuable optimization, especially for performance-sensitive scenarios. Well done!