refactor: reduce checking; just check once

This commit is contained in:
ToruNiina 2019-10-08 23:15:03 +09:00
parent e12fd4d944
commit d7b4d104d3

View File

@ -1384,9 +1384,10 @@ parse_inline_table(location<Container>& loc)
{ {
return err(kv_r.unwrap_err()); return err(kv_r.unwrap_err());
} }
const std::vector<key>& keys = kv_r.unwrap().first.first; const auto& kvpair = kv_r.unwrap();
const region<Container>& key_reg = kv_r.unwrap().first.second; const std::vector<key>& keys = kvpair.first.first;
const value_type& val = kv_r.unwrap().second; const region<Container>& key_reg = kvpair.first.second;
const value_type& val = kvpair.second;
const auto inserted = const auto inserted =
insert_nested_key(retval, val, keys.begin(), keys.end(), key_reg); insert_nested_key(retval, val, keys.begin(), keys.end(), key_reg);
@ -1771,9 +1772,10 @@ parse_ml_table(location<Container>& loc)
if(const auto kv = parse_key_value_pair<value_type>(loc)) if(const auto kv = parse_key_value_pair<value_type>(loc))
{ {
const std::vector<key>& keys = kv.unwrap().first.first; const auto& kvpair = kv.unwrap();
const region<Container>& key_reg = kv.unwrap().first.second; const std::vector<key>& keys = kvpair.first.first;
const value_type& val = kv.unwrap().second; const region<Container>& key_reg = kvpair.first.second;
const value_type& val = kvpair.second;
const auto inserted = const auto inserted =
insert_nested_key(tab, val, keys.begin(), keys.end(), key_reg); insert_nested_key(tab, val, keys.begin(), keys.end(), key_reg);
if(!inserted) if(!inserted)
@ -1889,8 +1891,9 @@ result<Value, std::string> parse_toml_file(location<Container>& loc)
const auto tab = parse_ml_table<value_type>(loc); const auto tab = parse_ml_table<value_type>(loc);
if(!tab){return err(tab.unwrap_err());} if(!tab){return err(tab.unwrap_err());}
const auto& keys = tabkey.unwrap().first; const auto& tk = tabkey.unwrap();
const auto& reg = tabkey.unwrap().second; const auto& keys = tk.first;
const auto& reg = tk.second;
const auto inserted = insert_nested_key(data, const auto inserted = insert_nested_key(data,
value_type(tab.unwrap(), reg), value_type(tab.unwrap(), reg),
@ -1905,8 +1908,9 @@ result<Value, std::string> parse_toml_file(location<Container>& loc)
const auto tab = parse_ml_table<value_type>(loc); const auto tab = parse_ml_table<value_type>(loc);
if(!tab){return err(tab.unwrap_err());} if(!tab){return err(tab.unwrap_err());}
const auto& keys = tabkey.unwrap().first; const auto& tk = tabkey.unwrap();
const auto& reg = tabkey.unwrap().second; const auto& keys = tk.first;
const auto& reg = tk.second;
const auto inserted = insert_nested_key(data, const auto inserted = insert_nested_key(data,
value_type(tab.unwrap(), reg), keys.begin(), keys.end(), reg); value_type(tab.unwrap(), reg), keys.begin(), keys.end(), reg);