|
21 | 21 | #include "string2int.h"
|
22 | 22 | #include "symbol_table.h"
|
23 | 23 |
|
24 |
| -unsigned get_max( |
| 24 | +static std::size_t smallest_unused_suffix( |
25 | 25 | const std::string &prefix,
|
26 | 26 | const symbol_tablet::symbolst &symbols)
|
27 | 27 | {
|
28 |
| - unsigned max_nr=0; |
| 28 | + std::size_t max_nr = 0; |
29 | 29 |
|
30 |
| - for(const auto &symbol_pair : symbols) |
31 |
| - { |
32 |
| - if(has_prefix(id2string(symbol_pair.first), prefix)) |
33 |
| - { |
34 |
| - max_nr = std::max( |
35 |
| - unsafe_string2unsigned( |
36 |
| - id2string(symbol_pair.first).substr(prefix.size())), |
37 |
| - max_nr); |
38 |
| - } |
39 |
| - } |
| 30 | + while(symbols.find(prefix + std::to_string(max_nr)) != symbols.end()) |
| 31 | + ++max_nr; |
40 | 32 |
|
41 | 33 | return max_nr;
|
42 | 34 | }
|
@@ -122,15 +114,15 @@ void namespace_baset::follow_macros(exprt &expr) const
|
122 | 114 | follow_macros(*it);
|
123 | 115 | }
|
124 | 116 |
|
125 |
| -unsigned namespacet::get_max(const std::string &prefix) const |
| 117 | +std::size_t namespacet::smallest_unused_suffix(const std::string &prefix) const |
126 | 118 | {
|
127 |
| - unsigned m=0; |
| 119 | + std::size_t m = 0; |
128 | 120 |
|
129 | 121 | if(symbol_table1!=nullptr)
|
130 |
| - m=std::max(m, ::get_max(prefix, symbol_table1->symbols)); |
| 122 | + m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table1->symbols)); |
131 | 123 |
|
132 | 124 | if(symbol_table2!=nullptr)
|
133 |
| - m=std::max(m, ::get_max(prefix, symbol_table2->symbols)); |
| 125 | + m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table2->symbols)); |
134 | 126 |
|
135 | 127 | return m;
|
136 | 128 | }
|
@@ -166,15 +158,13 @@ bool namespacet::lookup(
|
166 | 158 | return true;
|
167 | 159 | }
|
168 | 160 |
|
169 |
| -unsigned multi_namespacet::get_max(const std::string &prefix) const |
| 161 | +std::size_t |
| 162 | +multi_namespacet::smallest_unused_suffix(const std::string &prefix) const |
170 | 163 | {
|
171 |
| - unsigned m=0; |
| 164 | + std::size_t m = 0; |
172 | 165 |
|
173 |
| - for(symbol_table_listt::const_iterator |
174 |
| - it=symbol_table_list.begin(); |
175 |
| - it!=symbol_table_list.end(); |
176 |
| - it++) |
177 |
| - m=std::max(m, ::get_max(prefix, (*it)->symbols)); |
| 166 | + for(const auto &st : symbol_table_list) |
| 167 | + m = std::max(m, ::smallest_unused_suffix(prefix, st->symbols)); |
178 | 168 |
|
179 | 169 | return m;
|
180 | 170 | }
|
|
0 commit comments