diff --git a/src/ripple/app/consensus/LedgerConsensus.cpp b/src/ripple/app/consensus/LedgerConsensus.cpp index 3e88a4556..7d8b85438 100644 --- a/src/ripple/app/consensus/LedgerConsensus.cpp +++ b/src/ripple/app/consensus/LedgerConsensus.cpp @@ -44,6 +44,7 @@ #include #include #include +#include namespace ripple { @@ -1306,10 +1307,10 @@ private: s.set_ledgerseq (ledger.getLedgerSeq ()); s.set_networktime (getApp().getOPs ().getNetworkTimeNC ()); - uint256 hash = ledger.getParentHash (); - s.set_ledgerhashprevious (hash.begin (), hash.size ()); - hash = ledger.getHash (); - s.set_ledgerhash (hash.begin (), hash.size ()); + s.set_ledgerhashprevious(ledger.getParentHash ().begin (), + std::decay_t::bytes); + s.set_ledgerhash (ledger.getHash ().begin (), + std::decay_t::bytes); std::uint32_t uMin, uMax; if (!getApp().getOPs ().getFullValidatedRange (uMin, uMax)) diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 635985714..0f65e9a31 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -616,7 +616,8 @@ bool Ledger::getMetaHex (uint256 const& transID, std::string& hex) const return true; } -uint256 Ledger::getHash () +uint256 const& +Ledger::getHash () { if (!mValidHash) updateHash (); diff --git a/src/ripple/app/ledger/Ledger.h b/src/ripple/app/ledger/Ledger.h index bf48e07a5..48d33f040 100644 --- a/src/ripple/app/ledger/Ledger.h +++ b/src/ripple/app/ledger/Ledger.h @@ -187,7 +187,7 @@ public: void addRaw (Serializer & s) const; void setRaw (Serializer & s, bool hasPrefix); - uint256 getHash (); + uint256 const& getHash (); uint256 const& getParentHash () const { return mParentHash; diff --git a/src/ripple/basics/impl/strHex.cpp b/src/ripple/basics/impl/strHex.cpp index 965ca6809..dec02640f 100644 --- a/src/ripple/basics/impl/strHex.cpp +++ b/src/ripple/basics/impl/strHex.cpp @@ -19,22 +19,9 @@ #include #include - + namespace ripple { -char charHex (int iDigit) -{ - if (iDigit >= 0) - { - if(iDigit < 10) - return '0' + iDigit; - if(iDigit < 16) - return 'A' - 10 + iDigit; - } - - return 0; -} - int charUnHex (unsigned char c) { struct HexTab diff --git a/src/ripple/basics/strHex.h b/src/ripple/basics/strHex.h index ec0068d25..0212056de 100644 --- a/src/ripple/basics/strHex.h +++ b/src/ripple/basics/strHex.h @@ -26,14 +26,24 @@ #define RIPPLE_BASICS_STRHEX_H_INCLUDED #include - + namespace ripple { /** Converts an integer to the corresponding hex digit @param iDigit 0-15 inclusive - @return a character from '0'-'9' or 'A'-'F' on success; 0 on failure. + @return a character from '0'-'9' or 'A'-'F'. */ -char charHex (int iDigit); +inline +char +charHex (unsigned int digit) +{ + static + char const xtab[] = "0123456789ABCDEF"; + + assert (digit < 16); + + return xtab[digit]; +} /** @{ */ /** Converts a hex digit to the corresponding integer