mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-06-28 16:41:01 +03:00
fdr_compile: tidy up
This commit is contained in:
parent
466fc940e5
commit
88e6485e75
@ -124,10 +124,8 @@ void FDRCompiler::createInitialState(FDR *fdr) {
|
|||||||
// Find the minimum length for the literals in this bucket.
|
// Find the minimum length for the literals in this bucket.
|
||||||
const vector<LiteralIndex> &bucket_lits = bucketToLits[b];
|
const vector<LiteralIndex> &bucket_lits = bucketToLits[b];
|
||||||
u32 min_len = ~0U;
|
u32 min_len = ~0U;
|
||||||
for (vector<LiteralIndex>::const_iterator it = bucket_lits.begin(),
|
for (const LiteralIndex &lit_idx : bucket_lits) {
|
||||||
ite = bucket_lits.end();
|
min_len = min(min_len, verify_u32(lits[lit_idx].s.length()));
|
||||||
it != ite; ++it) {
|
|
||||||
min_len = min(min_len, verify_u32(lits[*it].s.length()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("bucket %u has min_len=%u\n", b, min_len);
|
DEBUG_PRINTF("bucket %u has min_len=%u\n", b, min_len);
|
||||||
@ -213,13 +211,11 @@ struct LitOrder {
|
|||||||
if (len1 != len2) {
|
if (len1 != len2) {
|
||||||
return len1 < len2;
|
return len1 < len2;
|
||||||
} else {
|
} else {
|
||||||
string::const_reverse_iterator it1, it2;
|
auto p = std::mismatch(i1s.rbegin(), i1s.rend(), i2s.rbegin());
|
||||||
tie(it1, it2) =
|
if (p.first == i1s.rend()) {
|
||||||
std::mismatch(i1s.rbegin(), i1s.rend(), i2s.rbegin());
|
|
||||||
if (it1 == i1s.rend()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return *it1 < *it2;
|
return *p.first < *p.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,9 +258,8 @@ void FDRCompiler::assignStringsToBuckets() {
|
|||||||
stable_sort(vli.begin(), vli.end(), LitOrder(lits));
|
stable_sort(vli.begin(), vli.end(), LitOrder(lits));
|
||||||
|
|
||||||
#ifdef DEBUG_ASSIGNMENT
|
#ifdef DEBUG_ASSIGNMENT
|
||||||
for (map<u32, u32>::iterator i = lenCounts.begin(), e = lenCounts.end();
|
for (const auto &m : lenCounts) {
|
||||||
i != e; ++i) {
|
printf("l<%u>:%u ", m.first, m.second);
|
||||||
printf("l<%d>:%d ", i->first, i->second);
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
#endif
|
#endif
|
||||||
@ -401,8 +396,7 @@ bool getMultiEntriesAtPosition(const FDREngineDescription &eng,
|
|||||||
distance = 4;
|
distance = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<LiteralIndex>::const_iterator i = vl.begin(), e = vl.end();
|
for (auto i = vl.begin(), e = vl.end(); i != e; ++i) {
|
||||||
i != e; ++i) {
|
|
||||||
if (e - i > 5) {
|
if (e - i > 5) {
|
||||||
__builtin_prefetch(&lits[*(i + 5)]);
|
__builtin_prefetch(&lits[*(i + 5)]);
|
||||||
}
|
}
|
||||||
@ -456,31 +450,25 @@ void FDRCompiler::setupTab() {
|
|||||||
memcpy(tabIndexToMask(i), &defaultMask[0], mask_size);
|
memcpy(tabIndexToMask(i), &defaultMask[0], mask_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::map<u32, ue2::unordered_set<u32> > M2SET;
|
|
||||||
|
|
||||||
for (BucketIndex b = 0; b < eng.getNumBuckets(); b++) {
|
for (BucketIndex b = 0; b < eng.getNumBuckets(); b++) {
|
||||||
const vector<LiteralIndex> &vl = bucketToLits[b];
|
const vector<LiteralIndex> &vl = bucketToLits[b];
|
||||||
SuffixPositionInString pLimit = eng.getBucketWidth(b);
|
SuffixPositionInString pLimit = eng.getBucketWidth(b);
|
||||||
for (SuffixPositionInString pos = 0; pos < pLimit; pos++) {
|
for (SuffixPositionInString pos = 0; pos < pLimit; pos++) {
|
||||||
u32 bit = eng.getSchemeBit(b, pos);
|
u32 bit = eng.getSchemeBit(b, pos);
|
||||||
M2SET m2;
|
map<u32, ue2::unordered_set<u32>> m2;
|
||||||
bool done = getMultiEntriesAtPosition(eng, vl, lits, pos, m2);
|
bool done = getMultiEntriesAtPosition(eng, vl, lits, pos, m2);
|
||||||
if (done) {
|
if (done) {
|
||||||
clearbit(&defaultMask[0], bit);
|
clearbit(&defaultMask[0], bit);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (M2SET::const_iterator i = m2.begin(), e = m2.end(); i != e;
|
for (const auto &elem : m2) {
|
||||||
++i) {
|
u32 dc = elem.first;
|
||||||
u32 dc = i->first;
|
const ue2::unordered_set<u32> &mskSet = elem.second;
|
||||||
const ue2::unordered_set<u32> &mskSet = i->second;
|
|
||||||
u32 v = ~dc;
|
u32 v = ~dc;
|
||||||
do {
|
do {
|
||||||
u32 b2 = v & dc;
|
u32 b2 = v & dc;
|
||||||
for (ue2::unordered_set<u32>::const_iterator
|
for (const u32 &mskVal : mskSet) {
|
||||||
i2 = mskSet.begin(),
|
u32 val = (mskVal & ~dc) | b2;
|
||||||
e2 = mskSet.end();
|
|
||||||
i2 != e2; ++i2) {
|
|
||||||
u32 val = (*i2 & ~dc) | b2;
|
|
||||||
clearbit(tabIndexToMask(val), bit);
|
clearbit(tabIndexToMask(val), bit);
|
||||||
}
|
}
|
||||||
v = (v + (dc & -dc)) | ~dc;
|
v = (v + (dc & -dc)) | ~dc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user