Skip to content

Commit 594df72

Browse files
committed
Drop internal string tracking
1 parent b667a43 commit 594df72

File tree

6 files changed

+9
-54
lines changed

6 files changed

+9
-54
lines changed

include/scratchcpp/string_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct StringPtr;
1111

1212
extern "C"
1313
{
14-
LIBSCRATCHCPP_EXPORT StringPtr *string_pool_new(bool internal = true);
14+
LIBSCRATCHCPP_EXPORT StringPtr *string_pool_new();
1515
LIBSCRATCHCPP_EXPORT void string_pool_free(StringPtr *str);
1616
}
1717

src/engine/internal/engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Engine::Engine() :
5050
m_clock(Clock::instance().get()),
5151
m_audioEngine(IAudioEngine::instance())
5252
{
53-
m_answer = string_pool_new(false);
53+
m_answer = string_pool_new();
5454
string_assign_cstring(m_answer, "");
5555

5656
m_questionAnswered.connect([this](const std::string &answer) {

src/engine/internal/llvm/llvmbuildutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ void LLVMBuildUtils::createValueStore(
815815

816816
// Create a new string, change type and assign
817817
llvm::Value *ptr = m_builder.CreateStructGEP(m_valueDataType, destPtr, 0);
818-
llvm::Value *destStringPtr = m_builder.CreateCall(m_functions.resolve_string_pool_new(), m_builder.getInt1(false));
818+
llvm::Value *destStringPtr = m_builder.CreateCall(m_functions.resolve_string_pool_new());
819819

820820
m_builder.CreateStore(m_builder.getInt32(static_cast<uint32_t>(ValueType::String)), destTypePtr);
821821
m_builder.CreateStore(destStringPtr, ptr);
@@ -879,7 +879,7 @@ void LLVMBuildUtils::createValueStore(
879879

880880
// Create a new string, change type and assign
881881
llvm::Value *ptr = m_builder.CreateStructGEP(m_valueDataType, destPtr, 0);
882-
llvm::Value *destStringPtr = m_builder.CreateCall(m_functions.resolve_string_pool_new(), m_builder.getInt1(false));
882+
llvm::Value *destStringPtr = m_builder.CreateCall(m_functions.resolve_string_pool_new());
883883

884884
m_builder.CreateStore(m_builder.getInt32(static_cast<uint32_t>(ValueType::String)), destTypePtr);
885885
m_builder.CreateStore(destStringPtr, ptr);

src/engine/internal/llvm/llvmfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ llvm::FunctionCallee LLVMFunctions::resolve_llvm_get_string_array()
284284

285285
llvm::FunctionCallee LLVMFunctions::resolve_string_pool_new()
286286
{
287-
return resolveFunction("string_pool_new", llvm::FunctionType::get(m_stringPtrType->getPointerTo(), { m_builder->getInt1Ty() }, false));
287+
return resolveFunction("string_pool_new", llvm::FunctionType::get(m_stringPtrType->getPointerTo(), false));
288288
}
289289

290290
llvm::FunctionCallee LLVMFunctions::resolve_string_pool_free()

src/scratch/string_pool.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,30 @@
55
#include <scratchcpp/string_functions.h>
66
#include <memory>
77
#include <unordered_set>
8-
#include <unordered_map>
98
#include <map>
109
#include <cassert>
1110
#include <algorithm>
1211

1312
namespace libscratchcpp
1413
{
1514

16-
class Thread;
17-
1815
static std::unordered_set<std::unique_ptr<StringPtr>> strings;
1916
static std::multimap<size_t, StringPtr *> freeStrings; // sorted by allocated space
2017

21-
static std::unordered_map<Thread *, std::unordered_set<StringPtr *>> threadStrings;
22-
static Thread *currentThread = nullptr;
23-
2418
extern "C"
2519
{
2620
/*!
2721
* Use this instead of dynamically allocating StringPtr.
28-
* \param[in] internal Whether the string should be deallocated when the current thread is removed (it's only used within the thread).
2922
* \note The returned string is uninitialized. Use e. g. string_assign_cstring() to initialize it.
3023
*/
31-
StringPtr *string_pool_new(bool internal)
24+
StringPtr *string_pool_new()
3225
{
3326
if (freeStrings.empty()) {
3427
auto str = std::make_unique<StringPtr>();
3528
StringPtr *ptr = str.get();
3629
assert(strings.find(str) == strings.cend());
3730
strings.insert(std::move(str));
3831

39-
if (internal && currentThread)
40-
threadStrings[currentThread].insert(ptr);
41-
4232
return ptr;
4333
}
4434

@@ -47,51 +37,16 @@ extern "C"
4737
StringPtr *ptr = last->second;
4838
freeStrings.erase(last);
4939

50-
if (internal && currentThread)
51-
threadStrings[currentThread].insert(ptr);
52-
5340
return ptr;
5441
}
5542

5643
/*! Invalidates the given StringPtr so that it can be used for new strings later. */
5744
void string_pool_free(StringPtr *str)
5845
{
59-
if (currentThread)
60-
threadStrings[currentThread].erase(str);
61-
6246
assert(std::find_if(freeStrings.begin(), freeStrings.end(), [str](const std::pair<size_t, StringPtr *> &p) { return p.second == str; }) == freeStrings.end());
6347
assert(std::find_if(strings.begin(), strings.end(), [str](const std::unique_ptr<StringPtr> &p) { return p.get() == str; }) != strings.end());
6448
freeStrings.insert(std::pair<size_t, StringPtr *>(str->allocatedSize, str));
6549
}
6650
}
6751

68-
/* string_pool_p.h */
69-
70-
void string_pool_add_thread(Thread *thread)
71-
{
72-
// Start capturing allocated strings in the thread
73-
assert(threadStrings.find(thread) == threadStrings.cend());
74-
threadStrings[thread] = {};
75-
}
76-
77-
void string_pool_remove_thread(Thread *thread)
78-
{
79-
// Free all strings in the thread (garbage collection)
80-
assert(threadStrings.find(thread) != threadStrings.cend());
81-
auto &strings = threadStrings[thread];
82-
83-
for (StringPtr *str : strings)
84-
freeStrings.insert(std::pair<size_t, StringPtr *>(str->allocatedSize, str));
85-
86-
threadStrings.erase(thread);
87-
88-
if (currentThread == thread)
89-
currentThread = nullptr;
90-
}
91-
92-
void string_pool_set_thread(Thread *thread)
93-
{
94-
currentThread = thread;
95-
}
96-
9752
} // namespace libscratchcpp

src/scratch/value_functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ extern "C"
6363
void value_assign_cstring(ValueData *v, const char *stringValue)
6464
{
6565
if (v->type != ValueType::String) {
66-
v->stringValue = string_pool_new(false);
66+
v->stringValue = string_pool_new();
6767
v->type = ValueType::String;
6868
}
6969

@@ -74,7 +74,7 @@ extern "C"
7474
void value_assign_stringPtr(ValueData *v, const StringPtr *stringValue)
7575
{
7676
if (v->type != ValueType::String) {
77-
v->stringValue = string_pool_new(false);
77+
v->stringValue = string_pool_new();
7878
v->type = ValueType::String;
7979
}
8080

@@ -103,7 +103,7 @@ extern "C"
103103
if (v->type == ValueType::String)
104104
string_assign(v->stringValue, another->stringValue);
105105
else {
106-
v->stringValue = string_pool_new(false);
106+
v->stringValue = string_pool_new();
107107
string_assign(v->stringValue, another->stringValue);
108108
v->type = ValueType::String;
109109
}

0 commit comments

Comments
 (0)