mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
perf: cache current line number in location
`location::line_num()` function used to be implemented by using `std::count`, so each time the parser encounters a type mismatch, `std::count` was called with almost whole file. It decelerates the parsing process too much, so I decided to add `line_number_` member variable to `location` and add `advance/retrace/reset` to `location` in order to modify the position that is pointed.
This commit is contained in:
@@ -39,7 +39,7 @@ inline ::toml::value operator""_toml(const char* str, std::size_t len)
|
||||
// literal is a TOML file (i.e. multiline table).
|
||||
if(auto data = ::toml::detail::parse_toml_file(loc))
|
||||
{
|
||||
loc.iter() = loc.begin(); // rollback to the top of the literal
|
||||
loc.reset(loc.begin()); // rollback to the top of the literal
|
||||
return ::toml::value(std::move(data.unwrap()),
|
||||
::toml::detail::region<std::vector<char>>(std::move(loc)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user