Avoid copying and improve optimization opportunities

This commit is contained in:
Nik Bougalis
2015-03-27 13:35:57 -07:00
committed by Tom Ritchford
parent b4058a813b
commit f072b5b679
5 changed files with 22 additions and 23 deletions

View File

@@ -44,6 +44,7 @@
#include <ripple/protocol/UintTypes.h> #include <ripple/protocol/UintTypes.h>
#include <beast/module/core/text/LexicalCast.h> #include <beast/module/core/text/LexicalCast.h>
#include <beast/utility/make_lock.h> #include <beast/utility/make_lock.h>
#include <type_traits>
namespace ripple { namespace ripple {
@@ -1306,10 +1307,10 @@ private:
s.set_ledgerseq (ledger.getLedgerSeq ()); s.set_ledgerseq (ledger.getLedgerSeq ());
s.set_networktime (getApp().getOPs ().getNetworkTimeNC ()); s.set_networktime (getApp().getOPs ().getNetworkTimeNC ());
uint256 hash = ledger.getParentHash (); s.set_ledgerhashprevious(ledger.getParentHash ().begin (),
s.set_ledgerhashprevious (hash.begin (), hash.size ()); std::decay_t<decltype(ledger.getParentHash ())>::bytes);
hash = ledger.getHash (); s.set_ledgerhash (ledger.getHash ().begin (),
s.set_ledgerhash (hash.begin (), hash.size ()); std::decay_t<decltype(ledger.getHash ())>::bytes);
std::uint32_t uMin, uMax; std::uint32_t uMin, uMax;
if (!getApp().getOPs ().getFullValidatedRange (uMin, uMax)) if (!getApp().getOPs ().getFullValidatedRange (uMin, uMax))

View File

@@ -616,7 +616,8 @@ bool Ledger::getMetaHex (uint256 const& transID, std::string& hex) const
return true; return true;
} }
uint256 Ledger::getHash () uint256 const&
Ledger::getHash ()
{ {
if (!mValidHash) if (!mValidHash)
updateHash (); updateHash ();

View File

@@ -187,7 +187,7 @@ public:
void addRaw (Serializer & s) const; void addRaw (Serializer & s) const;
void setRaw (Serializer & s, bool hasPrefix); void setRaw (Serializer & s, bool hasPrefix);
uint256 getHash (); uint256 const& getHash ();
uint256 const& getParentHash () const uint256 const& getParentHash () const
{ {
return mParentHash; return mParentHash;

View File

@@ -19,22 +19,9 @@
#include <BeastConfig.h> #include <BeastConfig.h>
#include <algorithm> #include <algorithm>
namespace ripple { 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) int charUnHex (unsigned char c)
{ {
struct HexTab struct HexTab

View File

@@ -26,14 +26,24 @@
#define RIPPLE_BASICS_STRHEX_H_INCLUDED #define RIPPLE_BASICS_STRHEX_H_INCLUDED
#include <string> #include <string>
namespace ripple { namespace ripple {
/** Converts an integer to the corresponding hex digit /** Converts an integer to the corresponding hex digit
@param iDigit 0-15 inclusive @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 /** Converts a hex digit to the corresponding integer