Commit da28db02 authored by s_kleplj's avatar s_kleplj
Browse files

spaces are added by children, shorter hashing

parent 2fcd607c
...@@ -95,10 +95,7 @@ bool macroprocessor_impl::process( ...@@ -95,10 +95,7 @@ bool macroprocessor_impl::process(
for (std::size_t i = 0; i < parsed.size(); ++i) { for (std::size_t i = 0; i < parsed.size(); ++i) {
if (found[i] != nullptr) { if (found[i] != nullptr) {
if (found[i]->length > 0) { found[i]->append_to(output);
found[i]->append_to(output);
output += ' ';
}
} else { } else {
output += parsed[i]; output += parsed[i];
output += ' '; output += ' ';
......
...@@ -31,6 +31,20 @@ struct policy_avx512 { ...@@ -31,6 +31,20 @@ struct policy_avx512 {
}; };
#endif #endif
template<std::size_t strength>
class view_hasher {
public:
std::size_t operator()(const std::string_view& a) const {
std::size_t ret = 0;
for (std::size_t i = 0; i < strength; ++i) {
ret *= 26;
ret += i < a.size() ? (a[i] | 32) - 'a' : 0;
}
return ret;
}
};
class macroprocessor_impl { class macroprocessor_impl {
public: public:
bool process(const std::string& s, std::string& output); bool process(const std::string& s, std::string& output);
...@@ -56,15 +70,13 @@ class macroprocessor_impl { ...@@ -56,15 +70,13 @@ class macroprocessor_impl {
if (value_.size() == 0 && length > 0) { if (value_.size() == 0 && length > 0) {
output += name_; output += name_;
output += ' ';
} else { } else {
for (word* w : value_) { for (word* w : value_) {
if (w->length > 0) { if (w->length > 0) {
w->append_to(output); w->append_to(output);
output += ' ';
} }
} }
output.pop_back();
} }
} }
...@@ -91,7 +103,7 @@ class macroprocessor_impl { ...@@ -91,7 +103,7 @@ class macroprocessor_impl {
std::size_t length; std::size_t length;
}; };
std::unordered_map<std::string_view, word> words_; std::unordered_map<std::string_view, word, view_hasher<3>> words_;
std::vector<std::string_view> parsed; std::vector<std::string_view> parsed;
std::vector<const word*> found; std::vector<const word*> found;
}; };
......
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