accel_dfa_build_strat: use small_vector for paths

This commit is contained in:
Justin Viiret 2017-04-10 11:05:06 +10:00 committed by Matthew Barr
parent 304bac3286
commit c9be18c7e2
3 changed files with 25 additions and 23 deletions

View File

@ -33,9 +33,11 @@
#include "nfagraph/ng_limex_accel.h" #include "nfagraph/ng_limex_accel.h"
#include "shufticompile.h" #include "shufticompile.h"
#include "trufflecompile.h" #include "trufflecompile.h"
#include "util/accel_scheme.h"
#include "util/charreach.h" #include "util/charreach.h"
#include "util/container.h" #include "util/container.h"
#include "util/dump_charclass.h" #include "util/dump_charclass.h"
#include "util/small_vector.h"
#include "util/verify_types.h" #include "util/verify_types.h"
#include <sstream> #include <sstream>
@ -49,16 +51,15 @@ namespace ue2 {
namespace { namespace {
struct path { struct path {
vector<CharReach> reach; small_vector<CharReach, MAX_ACCEL_DEPTH + 1> reach;
dstate_id_t dest = DEAD_STATE; dstate_id_t dest = DEAD_STATE;
explicit path(dstate_id_t base) : dest(base) { explicit path(dstate_id_t base) : dest(base) {}
}
}; };
}; };
static template<typename Container>
void dump_paths(const vector<path> &paths) { void dump_paths(const Container &paths) {
for (UNUSED const auto &p : paths) { for (UNUSED const path &p : paths) {
DEBUG_PRINTF("[%s] -> %u\n", describeClasses(p.reach).c_str(), p.dest); DEBUG_PRINTF("[%s] -> %u\n", describeClasses(p.reach).c_str(), p.dest);
} }
DEBUG_PRINTF("%zu paths\n", paths.size()); DEBUG_PRINTF("%zu paths\n", paths.size());
@ -113,14 +114,14 @@ void extend(const raw_dfa &rdfa, const path &p,
} else { } else {
path pp = append(p, CharReach(), p.dest); path pp = append(p, CharReach(), p.dest);
all[p.dest].push_back(pp); all[p.dest].push_back(pp);
out.push_back(pp); out.push_back(move(pp));
} }
} }
if (!s.reports_eod.empty()) { if (!s.reports_eod.empty()) {
path pp = append(p, CharReach(), p.dest); path pp = append(p, CharReach(), p.dest);
all[p.dest].push_back(pp); all[p.dest].push_back(pp);
out.push_back(pp); out.push_back(move(pp));
} }
map<u32, CharReach> dest; map<u32, CharReach> dest;
@ -140,7 +141,7 @@ void extend(const raw_dfa &rdfa, const path &p,
DEBUG_PRINTF("----good: [%s] -> %u\n", DEBUG_PRINTF("----good: [%s] -> %u\n",
describeClasses(pp.reach).c_str(), pp.dest); describeClasses(pp.reach).c_str(), pp.dest);
all[e.first].push_back(pp); all[e.first].push_back(pp);
out.push_back(pp); out.push_back(move(pp));
} }
} }
@ -162,8 +163,10 @@ vector<vector<CharReach>> generate_paths(const raw_dfa &rdfa,
dump_paths(paths); dump_paths(paths);
vector<vector<CharReach>> rv; vector<vector<CharReach>> rv;
rv.reserve(paths.size());
for (auto &p : paths) { for (auto &p : paths) {
rv.push_back(move(p.reach)); rv.push_back(vector<CharReach>(std::make_move_iterator(p.reach.begin()),
std::make_move_iterator(p.reach.end())));
} }
return rv; return rv;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2016, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -249,15 +249,6 @@ string describeClass(const CharReach &cr, size_t maxLength,
return oss.str(); return oss.str();
} }
string describeClasses(const std::vector<CharReach> &v, size_t maxClassLength,
enum cc_output_t out_type) {
std::ostringstream oss;
for (const auto &cr : v) {
describeClass(oss, cr, maxClassLength, out_type);
}
return oss.str();
}
// C stdio wrapper // C stdio wrapper
void describeClass(FILE *f, const CharReach &cr, size_t maxLength, void describeClass(FILE *f, const CharReach &cr, size_t maxLength,
enum cc_output_t out_type) { enum cc_output_t out_type) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015-2016, Intel Corporation * Copyright (c) 2015-2017, Intel Corporation
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -37,6 +37,7 @@
#include <cstdio> #include <cstdio>
#include <ostream> #include <ostream>
#include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
@ -55,9 +56,16 @@ void describeClass(std::ostream &os, const CharReach &cr, size_t maxLength = 16,
std::string describeClass(const CharReach &cr, size_t maxLength = 16, std::string describeClass(const CharReach &cr, size_t maxLength = 16,
enum cc_output_t out_type = CC_OUT_TEXT); enum cc_output_t out_type = CC_OUT_TEXT);
std::string describeClasses(const std::vector<CharReach> &v, template<typename Container>
std::string describeClasses(const Container &container,
size_t maxClassLength = 16, size_t maxClassLength = 16,
enum cc_output_t out_type = CC_OUT_TEXT); enum cc_output_t out_type = CC_OUT_TEXT) {
std::ostringstream oss;
for (const CharReach &cr : container) {
describeClass(oss, cr, maxClassLength, out_type);
}
return oss.str();
}
void describeClass(FILE *f, const CharReach &cr, size_t maxLength, void describeClass(FILE *f, const CharReach &cr, size_t maxLength,
enum cc_output_t out_type); enum cc_output_t out_type);