Skip to content

Commit d683a70

Browse files
authored
Merge pull request diffblue#3110 from diffblue/to_dstring
introduce to_dstring
2 parents ae7379d + e3f19d2 commit d683a70

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/util/dstring.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ std::ostream &dstringt::operator<<(std::ostream &out) const
1717
{
1818
return out << as_string();
1919
}
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+
}

src/util/dstring.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <string>
1717

1818
#include "invariant.h"
19+
#include "magic.h"
1920
#include "string_container.h"
2021

2122
/// \ref dstringt has one field, an unsigned integer \ref no which is an index
@@ -220,4 +221,19 @@ struct diagnostics_helpert<dstringt>
220221
}
221222
};
222223

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+
223239
#endif // CPROVER_UTIL_DSTRING_H

src/util/irep.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ long long irept::get_long_long(const irep_namet &name) const
126126

127127
void irept::set(const irep_namet &name, const long long value)
128128
{
129+
#ifdef USE_DSTRING
130+
add(name).id(to_dstring(value));
131+
#else
129132
add(name).id(std::to_string(value));
133+
#endif
130134
}
131135

132136
void irept::remove(const irep_namet &name)

src/util/magic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ const std::size_t STRING_REFINEMENT_MAX_CHAR_WIDTH = 16;
1313
// Limit the size of strings in traces to 64M chars to avoid memout
1414
const std::size_t MAX_CONCRETE_STRING_SIZE = 1 << 26;
1515

16+
// The top end of the range of integers for which dstrings are precomputed
17+
constexpr std::size_t DSTRING_NUMBERS_MAX = 64;
18+
1619
#endif

0 commit comments

Comments
 (0)