Optimize account_lines and account_offers (RIPD-587)

Conflicts:
	src/ripple/app/ledger/Ledger.h
This commit is contained in:
Miguel Portilla
2014-09-22 12:16:18 -04:00
committed by Nik Bougalis
parent 0f71b4a378
commit f14d75e798
4 changed files with 304 additions and 182 deletions

View File

@@ -1382,6 +1382,89 @@ void Ledger::visitAccountItems (
}
bool Ledger::visitAccountItems (
Account const& accountID,
uint256 const& startAfter,
std::uint64_t const hint,
unsigned int limit,
std::function <bool (SLE::ref)> func) const
{
// Visit each item in this account's owner directory
uint256 const rootIndex (Ledger::getOwnerDirIndex (accountID));
uint256 currentIndex (rootIndex);
// If startAfter is not zero try jumping to that page using the hint
if (startAfter.isNonZero ())
{
uint256 const hintIndex (getDirNodeIndex (rootIndex, hint));
SLE::pointer hintDir (getSLEi (hintIndex));
if (hintDir != nullptr)
{
for (auto const& node : hintDir->getFieldV256 (sfIndexes))
{
if (node == startAfter)
{
// We found the hint, we can start here
currentIndex = hintIndex;
break;
}
}
}
bool found (false);
for (;;)
{
SLE::pointer ownerDir (getSLEi (currentIndex));
if (! ownerDir || ownerDir->getType () != ltDIR_NODE)
return found;
for (auto const& node : ownerDir->getFieldV256 (sfIndexes))
{
if (!found)
{
if (node == startAfter)
found = true;
}
else if (func (getSLEi (node)) && limit-- <= 1)
{
return found;
}
}
std::uint64_t const uNodeNext (ownerDir->getFieldU64 (sfIndexNext));
if (uNodeNext == 0)
return found;
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
}
}
else
{
for (;;)
{
SLE::pointer ownerDir (getSLEi (currentIndex));
if (! ownerDir || ownerDir->getType () != ltDIR_NODE)
return true;
for (auto const& node : ownerDir->getFieldV256 (sfIndexes))
{
if (func (getSLEi (node)) && limit-- <= 1)
return true;
}
std::uint64_t const uNodeNext (ownerDir->getFieldU64 (sfIndexNext));
if (uNodeNext == 0)
return true;
currentIndex = Ledger::getDirNodeIndex (rootIndex, uNodeNext);
}
}
}
static void visitHelper (
std::function<void (SLE::ref)>& function, SHAMapItem::ref item)
{
@@ -1785,12 +1868,20 @@ uint256 Ledger::getRippleStateIndex (
{
Serializer s (62);
bool const bAltB = a < b;
s.add16 (spaceRipple); // 2
s.add16 (spaceRipple); // 2
s.add160 (bAltB ? a : b); // 20
s.add160 (bAltB ? b : a); // 20
s.add160 (currency); // 20
if (a < b)
{
s.add160 (a); // 20
s.add160 (b); // 20
}
else
{
s.add160 (b); // 20
s.add160 (a); // 20
}
s.add160 (currency); // 20
return s.getSHA512Half ();
}