Remove lvalue overload of SHAMap::addItem:

This overload was mistakenly used, but not needed
in the Ledger logic.  Removing this overload turns
this performance bug into a compile time error.
This commit is contained in:
Howard Hinnant
2016-01-14 13:41:29 -05:00
committed by Nik Bougalis
parent a1582c610e
commit bdb1966573
6 changed files with 12 additions and 18 deletions

View File

@@ -416,7 +416,7 @@ Ledger::setAccepted(NetClock::time_point closeTime,
bool Ledger::addSLE (SLE const& sle)
{
SHAMapItem item (sle.getIndex(), sle.getSerializer());
return stateMap_->addItem(item, false, false);
return stateMap_->addItem(std::move(item), false, false);
}
//------------------------------------------------------------------------------

View File

@@ -137,7 +137,6 @@ public:
// normal hash access functions
bool hasItem (uint256 const& id) const;
bool delItem (uint256 const& id);
bool addItem (SHAMapItem const& i, bool isTransaction, bool hasMeta);
bool addItem (SHAMapItem&& i, bool isTransaction, bool hasMeta);
SHAMapHash getHash () const;
@@ -193,12 +192,10 @@ public:
int flushDirty (NodeObjectType t, std::uint32_t seq);
void walkMap (std::vector<SHAMapMissingNode>& missingNodes, int maxMissing) const;
bool deepCompare (SHAMap & other) const;
bool deepCompare (SHAMap & other) const; // Intended for debug/test only
using fetchPackEntry_t = std::pair <uint256, Blob>;
void visitDifferences(SHAMap* have, std::function<bool(SHAMapAbstractNode&)>) const;
void getFetchPack (SHAMap * have, bool includeLeaves, int max,
std::function<void (SHAMapHash const&, const Blob&)>) const;
@@ -212,6 +209,7 @@ private:
using DeltaRef = std::pair<std::shared_ptr<SHAMapItem const> const&,
std::shared_ptr<SHAMapItem const> const&>;
void visitDifferences(SHAMap* have, std::function<bool(SHAMapAbstractNode&)>) const;
int unshare ();
// tree node cache operations

View File

@@ -755,11 +755,6 @@ SHAMap::addGiveItem (std::shared_ptr<SHAMapItem const> const& item,
return true;
}
bool SHAMap::addItem (const SHAMapItem& i, bool isTransaction, bool hasMetaData)
{
return addGiveItem(std::make_shared<SHAMapItem const>(i), isTransaction, hasMetaData);
}
bool
SHAMap::addItem(SHAMapItem&& i, bool isTransaction, bool hasMetaData)
{

View File

@@ -103,7 +103,7 @@ public:
{
std::shared_ptr <SHAMapItem> item (
make_random_item (r));
auto const result (t.addItem (*item, false, false));
auto const result (t.addItem (std::move(*item), false, false));
assert (result);
(void) result;
}

View File

@@ -75,8 +75,8 @@ public:
sMap.setUnbacked ();
SHAMapItem i1 (h1, IntToVUC (1)), i2 (h2, IntToVUC (2)), i3 (h3, IntToVUC (3)), i4 (h4, IntToVUC (4)), i5 (h5, IntToVUC (5));
unexpected (!sMap.addItem (i2, true, false), "no add");
unexpected (!sMap.addItem (i1, true, false), "no add");
unexpected (!sMap.addItem (SHAMapItem{i2}, true, false), "no add");
unexpected (!sMap.addItem (SHAMapItem{i1}, true, false), "no add");
auto i = sMap.begin();
auto e = sMap.end();
@@ -85,9 +85,9 @@ public:
unexpected (i == e || (*i != i2), "bad traverse");
++i;
unexpected (i != e, "bad traverse");
sMap.addItem (i4, true, false);
sMap.addItem (SHAMapItem{i4}, true, false);
sMap.delItem (i2.key());
sMap.addItem (i3, true, false);
sMap.addItem (SHAMapItem{i3}, true, false);
i = sMap.begin();
e = sMap.end();
unexpected (i == e || (*i != i1), "bad traverse");
@@ -110,6 +110,7 @@ public:
unexpected (!sMap.delItem (sMap.begin()->key()), "bad mod");
unexpected (sMap.getHash () == mapHash, "bad snapshot");
unexpected (map2->getHash () != mapHash, "bad snapshot");
sMap.dump();
if (backed)
testcase ("build/tear backed");
@@ -144,7 +145,7 @@ public:
for (int i = 0; i < keys.size(); ++i)
{
SHAMapItem item (keys[i], IntToVUC (i));
expect (map.addItem (item, true, false), "unable to add item");
expect (map.addItem (std::move(item), true, false), "unable to add item");
expect (map.getHash().as_uint256() == hashes[i], "bad buildup map hash");
}
for (int i = keys.size() - 1; i >= 0; --i)

View File

@@ -59,7 +59,7 @@ public:
std::shared_ptr<SHAMapItem> item = makeRandomAS ();
items.push_back (item->key());
if (!map.addItem (*item, false, false))
if (!map.addItem (std::move(*item), false, false))
{
log <<
"Unable to add item to map";
@@ -99,7 +99,7 @@ public:
int items = 10000;
for (int i = 0; i < items; ++i)
source.addItem (*makeRandomAS (), false, false);
source.addItem (std::move(*makeRandomAS ()), false, false);
unexpected (!confuseMap (source, 500), "ConfuseMap");