mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
StorageEntry: Also store copy of name here.
This wastes a bit of space but is necessary for assign message generation.
This commit is contained in:
@@ -40,7 +40,7 @@ bool Storage::SetEntryValue(StringRef name, std::shared_ptr<Value> value) {
|
||||
if (!value) return true;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto& entry = m_entries[name];
|
||||
if (!entry) entry = std::make_shared<StorageEntry>();
|
||||
if (!entry) entry = std::make_shared<StorageEntry>(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> value) {
|
||||
if (!value) return;
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto& entry = m_entries[name];
|
||||
if (!entry) entry = std::make_shared<StorageEntry>();
|
||||
if (!entry) entry = std::make_shared<StorageEntry>(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<std::mutex> lock(m_mutex);
|
||||
for (auto& i : entries) {
|
||||
auto& entry = m_entries[i.first];
|
||||
if (!entry) entry = std::make_shared<StorageEntry>();
|
||||
if (!entry) entry = std::make_shared<StorageEntry>(i.first);
|
||||
auto old_value = entry->value();
|
||||
entry->set_value(i.second);
|
||||
bool was_persist = entry->IsPersistent();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ class StorageTest : public ::testing::Test {
|
||||
Storage::UpdateQueue& updates() { return storage.updates(); }
|
||||
std::shared_ptr<StorageEntry> GetEntry(StringRef name) {
|
||||
auto& entry = storage.m_entries[name];
|
||||
if (!entry) entry = std::make_shared<StorageEntry>();
|
||||
if (!entry) entry = std::make_shared<StorageEntry>(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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user