Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/support/istring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "istring.h"
#include "mixed_arena.h"

namespace wasm {

Expand Down Expand Up @@ -45,9 +46,9 @@ std::string_view IString::interned(std::string_view s, bool reuse) {

// The global backing store for interned strings that do not otherwise have
// stable addresses.
static std::vector<std::vector<char>> allocated;
static MixedArena arena;

// Guards access to `globalStrings` and `allocated`.
// Guards access to `globalStrings`. (note: `arena` is thread-safe anyhow)
static std::mutex mutex;

// A thread-local cache of strings to reduce contention.
Expand All @@ -72,12 +73,10 @@ std::string_view IString::interned(std::string_view s, bool reuse) {
// We have a new string, but it doesn't have a stable address. Create a copy
// of the data at a stable address we can use. Make sure it is null
// terminated so legacy uses that get a C string still work.
allocated.emplace_back();
auto& data = allocated.back();
data.reserve(s.size() + 1);
data.insert(data.end(), s.begin(), s.end());
data.push_back('\0');
s = std::string_view(allocated.back().data(), s.size());
char* data = (char*)arena.allocSpace(s.size() + 1, 1);
std::copy(s.begin(), s.end(), data);
data[s.size()] = '\0';
s = std::string_view(data, s.size());
}

// Intern our new string.
Expand Down
Loading