Optimize SHAMapItem construction

This commit is contained in:
Howard Hinnant
2015-09-01 16:49:43 -04:00
committed by Scott Schurr
parent 7ed2094a6a
commit d8aab5a749
4 changed files with 15 additions and 0 deletions

View File

@@ -138,6 +138,7 @@ public:
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);
uint256 getHash () const;
// save a copy if you have a temporary anyway

View File

@@ -40,6 +40,7 @@ private:
public:
SHAMapItem (uint256 const& tag, Blob const & data);
SHAMapItem (uint256 const& tag, Serializer const& s);
SHAMapItem (uint256 const& tag, Serializer&& s);
Slice slice() const;

View File

@@ -798,6 +798,13 @@ 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)
{
return addGiveItem(std::make_shared<SHAMapItem const>(std::move(i)),
isTransaction, hasMetaData);
}
uint256
SHAMap::getHash () const
{

View File

@@ -37,4 +37,10 @@ SHAMapItem::SHAMapItem (uint256 const& tag, const Serializer& data)
{
}
SHAMapItem::SHAMapItem (uint256 const& tag, Serializer&& data)
: tag_ (tag)
, data_(std::move(data.modData()))
{
}
} // ripple