forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get_max: do not parse every symbol name in the symbol table
The typical case is that we have a small number of entries with the same prefix. Just perform that small number of name lookups (which are constant time after the log-time conversion from a string to an irep_idt). This speeds up function pointer removal on a build of the Linux kernel from 4610 seconds to just 86 seconds. Also rename get_max to smallest_unused_suffix to disambiguate the case of a symbol not being present, which in turn simplifies the use.
- Loading branch information
1 parent
b603703
commit ff25b2c
Showing
3 changed files
with
21 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,14 @@ Author: Daniel Kroening, [email protected] | |
#include "string2int.h" | ||
#include "symbol_table.h" | ||
|
||
unsigned get_max( | ||
static std::size_t smallest_unused_suffix( | ||
const std::string &prefix, | ||
const symbol_tablet::symbolst &symbols) | ||
{ | ||
unsigned max_nr=0; | ||
std::size_t max_nr = 0; | ||
|
||
for(const auto &symbol_pair : symbols) | ||
{ | ||
if(has_prefix(id2string(symbol_pair.first), prefix)) | ||
{ | ||
max_nr = std::max( | ||
unsafe_string2unsigned( | ||
id2string(symbol_pair.first).substr(prefix.size())), | ||
max_nr); | ||
} | ||
} | ||
while(symbols.find(prefix + std::to_string(max_nr)) != symbols.end()) | ||
++max_nr; | ||
|
||
return max_nr; | ||
} | ||
|
@@ -122,15 +114,15 @@ void namespace_baset::follow_macros(exprt &expr) const | |
follow_macros(*it); | ||
} | ||
|
||
unsigned namespacet::get_max(const std::string &prefix) const | ||
std::size_t namespacet::smallest_unused_suffix(const std::string &prefix) const | ||
{ | ||
unsigned m=0; | ||
std::size_t m = 0; | ||
|
||
if(symbol_table1!=nullptr) | ||
m=std::max(m, ::get_max(prefix, symbol_table1->symbols)); | ||
m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table1->symbols)); | ||
|
||
if(symbol_table2!=nullptr) | ||
m=std::max(m, ::get_max(prefix, symbol_table2->symbols)); | ||
m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table2->symbols)); | ||
|
||
return m; | ||
} | ||
|
@@ -166,15 +158,13 @@ bool namespacet::lookup( | |
return true; | ||
} | ||
|
||
unsigned multi_namespacet::get_max(const std::string &prefix) const | ||
std::size_t | ||
multi_namespacet::smallest_unused_suffix(const std::string &prefix) const | ||
{ | ||
unsigned m=0; | ||
std::size_t m = 0; | ||
|
||
for(symbol_table_listt::const_iterator | ||
it=symbol_table_list.begin(); | ||
it!=symbol_table_list.end(); | ||
it++) | ||
m=std::max(m, ::get_max(prefix, (*it)->symbols)); | ||
for(const auto &st : symbol_table_list) | ||
m = std::max(m, ::smallest_unused_suffix(prefix, st->symbols)); | ||
|
||
return m; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters