mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 19:10:11 +08:00
Avoid unnecessary copies of parser result
The 'result' class has unwrap() and unwrap_err() member functions overloaded for const lvalue and rvalue *this to avoid an unnecessarily copying the to-be unwrapped object of its containing object is going to be discarded anyway. Alas, the parse() function toml/parser.hpp file stored the parse result in a local `const` variable so, although the unwrap call would have been the last use of the object in each case, the unnecessary copy would still be made. This patch removes the `const` and adds a std::move() to actually benefit from the already implemented optimization.
This commit is contained in:
@@ -2414,12 +2414,14 @@ parse(std::vector<char>& letters, const std::string& fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto data = detail::parse_toml_file<value_type>(loc);
|
if (auto data = detail::parse_toml_file<value_type>(loc))
|
||||||
if(!data)
|
|
||||||
{
|
{
|
||||||
throw syntax_error(data.unwrap_err(), source_location(loc));
|
return std::move(data).unwrap();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw syntax_error(std::move(data).unwrap_err(), source_location(loc));
|
||||||
}
|
}
|
||||||
return data.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
Reference in New Issue
Block a user