optimize fct minify by counting call occurences
This commit is contained in:
parent
c5f505462f
commit
982e86cc87
4 changed files with 30 additions and 6 deletions
|
|
@ -29,6 +29,10 @@ extern set_t m_excluded_var, m_excluded_fct, m_excluded_cmd;
|
|||
|
||||
extern bool b_gotvar, b_gotfct, b_gotcmd;
|
||||
|
||||
// tools
|
||||
countmap_t combine_maps(countmap_t const& a, countmap_t const& b);
|
||||
countmap_t combine_common(countmap_t const& a, countmap_t const& b);
|
||||
|
||||
/** map get functions (optimizations) **/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -126,6 +126,17 @@ void concat_sets(std::set<T>& a, std::set<T> const& b)
|
|||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void exclude_sets(std::set<T>& a, std::set<T> const& b)
|
||||
{
|
||||
for(auto it: b)
|
||||
{
|
||||
auto t = a.find(it);
|
||||
if(t != a.end())
|
||||
a.erase(t);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool is_in_vector(T el, std::vector<T> vec)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -315,6 +315,7 @@ void minify_fct(_obj* in, std::regex const& exclude)
|
|||
concat_sets(excluded, unsets);
|
||||
concat_sets(excluded, all_reserved_words);
|
||||
// create mapping
|
||||
m_fcts = combine_common(m_fcts, m_cmds);
|
||||
fctmap=gen_minimal_map(m_fcts, excluded);
|
||||
// perform replace
|
||||
recurse(r_replace_fct, in, &fctmap);
|
||||
|
|
|
|||
|
|
@ -63,12 +63,7 @@ void require_rescan_all()
|
|||
// type tools
|
||||
countmap_t combine_maps(countmap_t const& a, countmap_t const& b)
|
||||
{
|
||||
countmap_t ret;
|
||||
for(auto it: a)
|
||||
{
|
||||
if(!ret.insert( it ).second)
|
||||
ret[it.first] += it.second;
|
||||
}
|
||||
countmap_t ret = a;
|
||||
for(auto it: b)
|
||||
{
|
||||
if(!ret.insert( it ).second)
|
||||
|
|
@ -77,6 +72,19 @@ countmap_t combine_maps(countmap_t const& a, countmap_t const& b)
|
|||
return ret;
|
||||
}
|
||||
|
||||
// add the values of b to a only if they are already present in a
|
||||
countmap_t combine_common(countmap_t const& a, countmap_t const& b)
|
||||
{
|
||||
countmap_t ret = a;
|
||||
for(auto it: a)
|
||||
{
|
||||
auto t=b.find(it.first);
|
||||
if(t!=b.end())
|
||||
ret[it.first] += t->second;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void list_map(countmap_t const& map)
|
||||
{
|
||||
uint32_t max=0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue