@@ -24,17 +24,18 @@ extern "C"
2424{
2525 /* !
2626 * Use this instead of dynamically allocating StringPtr.
27+ * \param[in] internal Whether the string should be deallocated when the current thread is removed (it's only used within the thread).
2728 * \note The returned string is uninitialized. Use e. g. string_assign_cstring() to initialize it.
2829 */
29- StringPtr *string_pool_new ()
30+ StringPtr *string_pool_new (bool internal )
3031 {
3132 if (freeStrings.empty ()) {
3233 auto str = std::make_unique<StringPtr>();
3334 StringPtr *ptr = str.get ();
3435 assert (strings.find (str) == strings.cend ());
3536 strings.insert (std::move (str));
3637
37- if (currentThread)
38+ if (internal && currentThread)
3839 threadStrings[currentThread].insert (ptr);
3940
4041 return ptr;
@@ -45,7 +46,7 @@ extern "C"
4546 StringPtr *ptr = last->second ;
4647 freeStrings.erase (last);
4748
48- if (currentThread)
49+ if (internal && currentThread)
4950 threadStrings[currentThread].insert (ptr);
5051
5152 return ptr;
@@ -54,10 +55,8 @@ extern "C"
5455 /* ! Invalidates the given StringPtr so that it can be used for new strings later. */
5556 void string_pool_free (StringPtr *str)
5657 {
57- if (currentThread) {
58- assert (threadStrings[currentThread].find (str) != threadStrings[currentThread].cend ());
58+ if (currentThread)
5959 threadStrings[currentThread].erase (str);
60- }
6160
6261 freeStrings.insert (std::pair<size_t , StringPtr *>(str->allocatedSize , str));
6362 }
0 commit comments