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:
ToruNiina
2019-04-12 18:32:46 +09:00
parent ea13e40889
commit 6f950c9ec8
4 changed files with 108 additions and 69 deletions

View File

@@ -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)));
}