Commit 2c205ff4 authored by s_kleplj's avatar s_kleplj
Browse files

optimizations of macro definition

parent 678550aa
......@@ -40,38 +40,37 @@ bool macroprocessor_impl::process(
if (is_def) {
if (parsed.size() != 1) {
auto tmp = std::vector<word*> {};
tmp.reserve(parsed.size() - 1);
for (auto i = parsed.begin() + 1; i != parsed.end(); ++i) {
auto it = words_.find(*i);
if (it != words_.end()) {
tmp.emplace_back(&it->second);
} else {
auto w_it = words_.emplace(*i, std::string{*i}).first;
const_cast<std::string_view&>(w_it->first) = w_it->second.name_;
tmp.emplace_back(&w_it->second);
}
}
std::vector<word*>* vector;
auto it = words_.find(parsed[0]);
if (it == words_.end()) {
auto w_it = words_.emplace(
it = words_.emplace(
std::piecewise_construct,
std::forward_as_tuple(parsed[0]),
std::forward_as_tuple(std::string {parsed[0]}, std::move(tmp))).first;
const_cast<std::string_view&>(w_it->first) = w_it->second.name_;
} else {
it->second.value_ = std::move(tmp);
std::forward_as_tuple(std::string {parsed[0]}, std::vector<word*>{})).first;
const_cast<std::string_view&>(it->first) = it->second.name_;
}
vector = &(it->second.value_);
vector->clear();
vector->reserve(parsed.size() - 1);
for (auto i = parsed.begin() + 1; i != parsed.end(); ++i) {
it = words_.find(*i);
if (it == words_.end()) {
it = words_.emplace(*i, std::string{*i}).first;
const_cast<std::string_view&>(it->first) = it->second.name_;
}
vector->emplace_back(&it->second);
}
} else {
auto it = words_.find(parsed[0]);
if (it == words_.end()) {
auto w_it = words_.emplace(
it = words_.emplace(
std::piecewise_construct,
std::forward_as_tuple(parsed[0]),
std::forward_as_tuple(std::string {parsed[0]}, std::vector<word*>{})).first;
const_cast<std::string_view&>(w_it->first) = w_it->second.name_;
const_cast<std::string_view&>(it->first) = it->second.name_;
} else {
it->second.value_ = {};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment