File tree Expand file tree Collapse file tree 4 files changed +17
-23
lines changed Expand file tree Collapse file tree 4 files changed +17
-23
lines changed Original file line number Diff line number Diff line change @@ -46,13 +46,13 @@ class dstringt final
4646
4747 // this one is not safe for static objects
4848 // NOLINTNEXTLINE(runtime/explicit)
49- dstringt (const char *s):no(string_container [s])
49+ dstringt (const char *s):no(get_string_container() [s])
5050 {
5151 }
5252
5353 // this one is not safe for static objects
5454 // NOLINTNEXTLINE(runtime/explicit)
55- dstringt (const std::string &s):no(string_container [s])
55+ dstringt (const std::string &s):no(get_string_container() [s])
5656 {
5757 }
5858
@@ -152,12 +152,12 @@ class dstringt final
152152
153153 // the reference returned is guaranteed to be stable
154154 const std::string &as_string () const
155- { return string_container .get_string (no); }
155+ { return get_string_container () .get_string (no); }
156156};
157157
158158// the reference returned is guaranteed to be stable
159159inline const std::string &as_string (const dstringt &s)
160- { return string_container .get_string (s.get_no ()); }
160+ { return get_string_container () .get_string (s.get_no ()); }
161161
162162// NOLINTNEXTLINE(readability/identifiers)
163163struct dstring_hash
Original file line number Diff line number Diff line change @@ -43,14 +43,15 @@ const char *irep_ids_table[]=
4343
4444#include " irep_ids.def" // NOLINT(build/include)
4545
46- void initialize_string_container ()
46+ string_containert::string_containert ()
4747{
48- // this is called by the constructor of string_containert
48+ // pre-allocate empty string -- this gets index 0
49+ get (" " );
4950
51+ // allocate strings
5052 for (unsigned i=0 ; irep_ids_table[i]!=nullptr ; i++)
5153 {
52- unsigned x;
53- x=string_container[irep_ids_table[i]];
54+ unsigned x=operator [](irep_ids_table[i]);
5455 INVARIANT (x==i, " i-th element is inserted at position i" ); // sanity check
5556 }
5657}
Original file line number Diff line number Diff line change @@ -13,8 +13,6 @@ Author: Daniel Kroening, kroening@kroening.com
1313
1414#include < cstring>
1515
16- string_containert string_container;
17-
1816string_ptrt::string_ptrt (const char *_s):s(_s), len(strlen(_s))
1917{
2018}
@@ -27,17 +25,6 @@ bool string_ptrt::operator==(const string_ptrt &other) const
2725 return len==0 || memcmp (s, other.s , len)==0 ;
2826}
2927
30- void initialize_string_container ();
31-
32- string_containert::string_containert ()
33- {
34- // pre-allocate empty string -- this gets index 0
35- get (" " );
36-
37- // allocate strings
38- initialize_string_container ();
39- }
40-
4128string_containert::~string_containert ()
4229{
4330}
@@ -87,3 +74,10 @@ unsigned string_containert::get(const std::string &s)
8774
8875 return r;
8976}
77+
78+ // / Get a reference to the global string container.
79+ string_containert &get_string_container ()
80+ {
81+ static string_containert ret;
82+ return ret;
83+ }
Original file line number Diff line number Diff line change @@ -89,7 +89,6 @@ class string_containert
8989 string_vectort string_vector;
9090};
9191
92- // an ugly global object
93- extern string_containert string_container;
92+ string_containert &get_string_container ();
9493
9594#endif // CPROVER_UTIL_STRING_CONTAINER_H
You can’t perform that action at this time.
0 commit comments