rose_build_add_mask: improve findMaskLiteral perf

This commit is contained in:
Justin Viiret
2017-08-15 13:57:43 +10:00
committed by Matthew Barr
parent 3b63a95f01
commit ba0bf0c991
3 changed files with 52 additions and 34 deletions

View File

@@ -291,18 +291,24 @@ void ue2_literal::push_back(char c, bool nc) {
s.push_back(c);
}
void ue2_literal::reverse() {
std::reverse(s.begin(), s.end());
const size_t len = nocase.size();
for (size_t i = 0; i < len / 2; i++) {
size_t j = len - i - 1;
bool a = nocase.test(i);
bool b = nocase.test(j);
nocase.set(i, b);
nocase.set(j, a);
}
}
// Return a copy of this literal in reverse order.
ue2_literal reverse_literal(const ue2_literal &in) {
ue2_literal rv;
if (in.empty()) {
return rv;
}
for (ue2_literal::const_iterator it = in.end(); it != in.begin();) {
--it;
rv.push_back(it->c, it->nocase);
}
return rv;
auto out = in;
out.reverse();
return out;
}
bool ue2_literal::operator<(const ue2_literal &b) const {

View File

@@ -191,6 +191,9 @@ public:
return a;
}
/// Reverse this literal in-place.
void reverse();
void operator+=(const ue2_literal &b);
bool operator==(const ue2_literal &b) const {
return s == b.s && nocase == b.nocase;