File tree 4 files changed +35
-0
lines changed 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -17,3 +17,15 @@ std::ostream &dstringt::operator<<(std::ostream &out) const
17
17
{
18
18
return out << as_string ();
19
19
}
20
+
21
+ dstringt get_dstring_number (std::size_t value)
22
+ {
23
+ static const dstringt *const dstring_numbers = [] {
24
+ dstringt *array = new dstringt[DSTRING_NUMBERS_MAX + 1 ];
25
+ for (std::size_t i = 0 ; i <= DSTRING_NUMBERS_MAX; i++)
26
+ array[i] = dstringt (std::to_string (i));
27
+ return array;
28
+ }();
29
+
30
+ return dstring_numbers[value];
31
+ }
Original file line number Diff line number Diff line change 16
16
#include < string>
17
17
18
18
#include " invariant.h"
19
+ #include " magic.h"
19
20
#include " string_container.h"
20
21
21
22
// / \ref dstringt has one field, an unsigned integer \ref no which is an index
@@ -220,4 +221,19 @@ struct diagnostics_helpert<dstringt>
220
221
}
221
222
};
222
223
224
+ dstringt get_dstring_number (std::size_t );
225
+
226
+ // / equivalent to dstringt(std::to_string(value)), i.e., produces a string
227
+ // / from a number
228
+ template <typename T>
229
+ static inline
230
+ typename std::enable_if<std::is_integral<T>::value, dstringt>::type
231
+ to_dstring (T value)
232
+ {
233
+ if (value >= 0 && value <= static_cast <T>(DSTRING_NUMBERS_MAX))
234
+ return get_dstring_number (value);
235
+ else
236
+ return std::to_string (value);
237
+ }
238
+
223
239
#endif // CPROVER_UTIL_DSTRING_H
Original file line number Diff line number Diff line change @@ -126,7 +126,11 @@ long long irept::get_long_long(const irep_namet &name) const
126
126
127
127
void irept::set (const irep_namet &name, const long long value)
128
128
{
129
+ #ifdef USE_DSTRING
130
+ add (name).id (to_dstring (value));
131
+ #else
129
132
add (name).id (std::to_string (value));
133
+ #endif
130
134
}
131
135
132
136
void irept::remove (const irep_namet &name)
Original file line number Diff line number Diff line change @@ -13,4 +13,7 @@ const std::size_t STRING_REFINEMENT_MAX_CHAR_WIDTH = 16;
13
13
// Limit the size of strings in traces to 64M chars to avoid memout
14
14
const std::size_t MAX_CONCRETE_STRING_SIZE = 1 << 26 ;
15
15
16
+ // The top end of the range of integers for which dstrings are precomputed
17
+ constexpr std::size_t DSTRING_NUMBERS_MAX = 64 ;
18
+
16
19
#endif
You can’t perform that action at this time.
0 commit comments