From fb1b82e2395c412f5d1d05f8da9bb30b1a0138c3 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 26 Jul 2015 10:28:20 -0700 Subject: [PATCH] StorageEntry: Also store copy of name here. This wastes a bit of space but is necessary for assign message generation. --- src/Storage.cpp | 6 +++--- src/Storage.h | 7 ++++++- test/unit/StorageTest.cpp | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Storage.cpp b/src/Storage.cpp index e0ca2accbd..96b4baa886 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -40,7 +40,7 @@ bool Storage::SetEntryValue(StringRef name, std::shared_ptr value) { if (!value) return true; std::lock_guard lock(m_mutex); auto& entry = m_entries[name]; - if (!entry) entry = std::make_shared(); + if (!entry) entry = std::make_shared(name); auto old_value = entry->value(); if (old_value && old_value->type() != value->type()) return false; // error on type mismatch @@ -58,7 +58,7 @@ void Storage::SetEntryTypeValue(StringRef name, std::shared_ptr value) { if (!value) return; std::lock_guard lock(m_mutex); auto& entry = m_entries[name]; - if (!entry) entry = std::make_shared(); + if (!entry) entry = std::make_shared(name); auto old_value = entry->value(); entry->set_value(value); if (!old_value || *old_value != *value) { @@ -551,7 +551,7 @@ next_line: std::lock_guard lock(m_mutex); for (auto& i : entries) { auto& entry = m_entries[i.first]; - if (!entry) entry = std::make_shared(); + if (!entry) entry = std::make_shared(i.first); auto old_value = entry->value(); entry->set_value(i.second); bool was_persist = entry->IsPersistent(); diff --git a/src/Storage.h b/src/Storage.h index b849675f17..9df9753265 100644 --- a/src/Storage.h +++ b/src/Storage.h @@ -27,7 +27,9 @@ class StorageTest; class StorageEntry { public: - StorageEntry() : m_id(0xffff) { m_flags = 0; } + StorageEntry(llvm::StringRef name) : m_name(name), m_id(0xffff) { + m_flags = 0; + } bool IsPersistent() const { return (m_flags & NT_PERSISTENT) != 0; } @@ -51,6 +53,8 @@ class StorageEntry { unsigned int flags() const { return m_flags; } void set_flags(unsigned int flags) { m_flags = flags; } + StringRef name() const { return m_name; } + unsigned int id() const { return m_id; } void set_id(unsigned int id) { m_id = id; } @@ -68,6 +72,7 @@ class StorageEntry { std::atomic_uint m_flags; // Only accessed from the Dispatcher, so these are NOT mutex-protected. + std::string m_name; unsigned int m_id; SequenceNumber m_seq_num; }; diff --git a/test/unit/StorageTest.cpp b/test/unit/StorageTest.cpp index eb3b43d293..8fbb997715 100644 --- a/test/unit/StorageTest.cpp +++ b/test/unit/StorageTest.cpp @@ -23,7 +23,7 @@ class StorageTest : public ::testing::Test { Storage::UpdateQueue& updates() { return storage.updates(); } std::shared_ptr GetEntry(StringRef name) { auto& entry = storage.m_entries[name]; - if (!entry) entry = std::make_shared(); + if (!entry) entry = std::make_shared(name); return entry; } Storage storage; @@ -121,6 +121,7 @@ TEST_F(StorageTest, StorageEntryInit) { EXPECT_FALSE(entry->value()); EXPECT_EQ(0u, entry->flags()); + EXPECT_EQ("foo", entry->name()); EXPECT_EQ(0xffffu, entry->id()); EXPECT_EQ(SequenceNumber(), entry->seq_num()); }