mocked_host: Apply suggestions from code review

This commit is contained in:
Paweł Bylica 2019-11-20 20:45:22 +01:00
parent b4ae4233f8
commit 52e09fc523
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 12 additions and 20 deletions

View File

@ -5,7 +5,6 @@
#include <evmc/evmc.hpp> #include <evmc/evmc.hpp>
#include <algorithm> #include <algorithm>
#include <iterator>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -76,9 +75,7 @@ public:
/// Equal operator. /// Equal operator.
bool operator==(const log_record& other) const noexcept bool operator==(const log_record& other) const noexcept
{ {
return creator == other.creator && data == other.data && return creator == other.creator && data == other.data && topics == other.topics;
topics.size() == other.topics.size() &&
std::equal(topics.begin(), topics.end(), other.topics.begin());
} }
}; };
@ -188,21 +185,19 @@ protected:
if (old.value == value) if (old.value == value)
return EVMC_STORAGE_UNCHANGED; return EVMC_STORAGE_UNCHANGED;
evmc_storage_status status; evmc_storage_status status{};
if (!old.dirty)
{ {
if (!old.dirty) old.dirty = true;
{ if (!old.value)
old.dirty = true; status = EVMC_STORAGE_ADDED;
if (!old.value) else if (value)
status = EVMC_STORAGE_ADDED; status = EVMC_STORAGE_MODIFIED;
else if (value)
status = EVMC_STORAGE_MODIFIED;
else
status = EVMC_STORAGE_DELETED;
}
else else
status = EVMC_STORAGE_MODIFIED_AGAIN; status = EVMC_STORAGE_DELETED;
} }
else
status = EVMC_STORAGE_MODIFIED_AGAIN;
old.value = value; old.value = value;
return status; return status;
@ -311,10 +306,7 @@ protected:
const bytes32 topics[], const bytes32 topics[],
size_t topics_count) noexcept override size_t topics_count) noexcept override
{ {
recorded_logs.push_back({addr, {data, data_size}, {}}); recorded_logs.push_back({addr, {data, data_size}, {topics, topics + topics_count}});
auto& record_topics = recorded_logs.back().topics;
record_topics.reserve(topics_count);
std::copy_n(topics, topics_count, std::back_inserter(record_topics));
} }
}; };
} // namespace evmc } // namespace evmc