Browse Source

Fix up rvalue references. Avoid a copy of an EVM code in ExtVM.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
42d9edc9b0
  1. 4
      libethereum/Account.h
  2. 2
      libethereum/VerifiedBlock.h
  3. 6
      libevm/ExtVMFace.cpp
  4. 2
      libevm/ExtVMFace.h
  5. 5
      libp2p/Session.cpp
  6. 4
      libtestutils/StateLoader.cpp
  7. 8
      mix/DebuggingStateWrapper.h
  8. 2
      mix/HttpServer.h
  9. 4
      test/TestHelper.cpp

4
libethereum/Account.h

@ -152,8 +152,7 @@ public:
h256 codeHash() const { assert(!isFreshCode()); return m_codeHash; } h256 codeHash() const { assert(!isFreshCode()); return m_codeHash; }
/// Sets the code of the account. Must only be called when isFreshCode() returns true. /// Sets the code of the account. Must only be called when isFreshCode() returns true.
void setCode(bytes&& _code) { assert(isFreshCode()); m_codeCache = _code; changed(); } void setCode(bytes&& _code) { assert(isFreshCode()); m_codeCache = std::move(_code); changed(); }
void setCode(bytes const& _code) { assert(isFreshCode()); m_codeCache = _code; changed(); }
/// @returns true if the account's code is available through code(). /// @returns true if the account's code is available through code().
bool codeCacheValid() const { return m_codeHash == EmptySHA3 || m_codeHash == c_contractConceptionCodeHash || m_codeCache.size(); } bool codeCacheValid() const { return m_codeHash == EmptySHA3 || m_codeHash == c_contractConceptionCodeHash || m_codeCache.size(); }
@ -206,4 +205,3 @@ private:
} }
} }

2
libethereum/VerifiedBlock.h

@ -47,7 +47,7 @@ struct VerifiedBlock
VerifiedBlock(BlockInfo&& _bi) VerifiedBlock(BlockInfo&& _bi)
{ {
verified.info = _bi; verified.info = std::move(_bi);
} }
VerifiedBlock(VerifiedBlock&& _other): VerifiedBlock(VerifiedBlock&& _other):

6
libevm/ExtVMFace.cpp

@ -21,22 +21,20 @@
#include "ExtVMFace.h" #include "ExtVMFace.h"
using namespace std;
using namespace dev; using namespace dev;
using namespace dev::eth; using namespace dev::eth;
ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes const& _code, h256 const& _codeHash, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, LastHashes const& _lh, unsigned _depth): ExtVMFace::ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, h256 const& _codeHash, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, LastHashes const& _lh, unsigned _depth):
myAddress(_myAddress), myAddress(_myAddress),
caller(_caller), caller(_caller),
origin(_origin), origin(_origin),
value(_value), value(_value),
gasPrice(_gasPrice), gasPrice(_gasPrice),
data(_data), data(_data),
code(_code), code(std::move(_code)),
codeHash(_codeHash), codeHash(_codeHash),
lastHashes(_lh), lastHashes(_lh),
previousBlock(_previousBlock), previousBlock(_previousBlock),
currentBlock(_currentBlock), currentBlock(_currentBlock),
depth(_depth) depth(_depth)
{} {}

2
libevm/ExtVMFace.h

@ -161,7 +161,7 @@ public:
ExtVMFace() = default; ExtVMFace() = default;
/// Full constructor. /// Full constructor.
ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes const& _code, h256 const& _codeHash, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, LastHashes const& _lh, unsigned _depth); ExtVMFace(Address _myAddress, Address _caller, Address _origin, u256 _value, u256 _gasPrice, bytesConstRef _data, bytes _code, h256 const& _codeHash, BlockInfo const& _previousBlock, BlockInfo const& _currentBlock, LastHashes const& _lh, unsigned _depth);
virtual ~ExtVMFace() = default; virtual ~ExtVMFace() = default;

5
libp2p/Session.cpp

@ -256,9 +256,8 @@ bool Session::checkPacket(bytesConstRef _msg)
void Session::send(bytes&& _msg) void Session::send(bytes&& _msg)
{ {
clog(NetLeft) << RLP(bytesConstRef(&_msg).cropped(1));
bytesConstRef msg(&_msg); bytesConstRef msg(&_msg);
clog(NetLeft) << RLP(msg.cropped(1));
if (!checkPacket(msg)) if (!checkPacket(msg))
clog(NetWarn) << "INVALID PACKET CONSTRUCTED!"; clog(NetWarn) << "INVALID PACKET CONSTRUCTED!";
@ -268,7 +267,7 @@ void Session::send(bytes&& _msg)
bool doWrite = false; bool doWrite = false;
{ {
Guard l(x_writeQueue); Guard l(x_writeQueue);
m_writeQueue.push_back(_msg); m_writeQueue.push_back(std::move(_msg));
doWrite = (m_writeQueue.size() == 1); doWrite = (m_writeQueue.size() == 1);
} }

4
libtestutils/StateLoader.cpp

@ -36,10 +36,10 @@ StateLoader::StateLoader(Json::Value const& _json, std::string const& _dbPath):
Address address = Address(name); Address address = Address(name);
bytes code = fromHex(o["code"].asString().substr(2)); bytes code = fromHex(o["code"].asString().substr(2));
if (code.size()) if (!code.empty())
{ {
m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::ContractConception); m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::ContractConception);
m_state.m_cache[address].setCode(code); m_state.m_cache[address].setCode(std::move(code));
} }
else else
m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::NormalCreation); m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::NormalCreation);

8
mix/DebuggingStateWrapper.h

@ -69,7 +69,7 @@ class QSolState: public QObject
public: public:
QSolState(QObject* _parent, QVariantMap&& _storage, QVariantList&& _callStack, QVariantMap&& _locals, int _start, int _end, QString _sourceName): QSolState(QObject* _parent, QVariantMap&& _storage, QVariantList&& _callStack, QVariantMap&& _locals, int _start, int _end, QString _sourceName):
QObject(_parent), m_storage(_storage), m_callStack(_callStack), m_locals(_locals), m_start(_start), m_end(_end), m_sourceName(_sourceName) QObject(_parent), m_storage(std::move(_storage)), m_callStack(std::move(_callStack)), m_locals(std::move(_locals)), m_start(_start), m_end(_end), m_sourceName(_sourceName)
{ } { }
private: private:
@ -92,7 +92,7 @@ class QCode: public QObject
Q_PROPERTY(QString documentId MEMBER m_document CONSTANT) Q_PROPERTY(QString documentId MEMBER m_document CONSTANT)
public: public:
QCode(QObject* _owner, QString const& _address, QVariantList&& _instrunctions): QObject(_owner), m_instructions(_instrunctions), m_address(_address) {} QCode(QObject* _owner, QString const& _address, QVariantList&& _instrunctions): QObject(_owner), m_instructions(std::move(_instrunctions)), m_address(_address) {}
void setDocument(QString const& _documentId) { m_document = _documentId; } void setDocument(QString const& _documentId) { m_document = _documentId; }
private: private:
@ -110,7 +110,7 @@ class QCallData: public QObject
Q_PROPERTY(QVariantList items MEMBER m_items CONSTANT) Q_PROPERTY(QVariantList items MEMBER m_items CONSTANT)
public: public:
QCallData(QObject* _owner, QVariantList&& _items): QObject(_owner), m_items(_items) {} QCallData(QObject* _owner, QVariantList&& _items): QObject(_owner), m_items(std::move(_items)) {}
private: private:
QVariantList m_items; QVariantList m_items;
@ -126,7 +126,7 @@ class QDebugData: public QObject
public: public:
QDebugData() { } QDebugData() { }
void setStates(QVariantList&& _states) { m_states = _states; } void setStates(QVariantList&& _states) { m_states = std::move(_states); }
private: private:
QVariantList m_states; QVariantList m_states;

2
mix/HttpServer.h

@ -46,7 +46,7 @@ class HttpRequest: public QObject
private: private:
HttpRequest(QObject* _parent, QUrl&& _url, QString&& _content, QVariantMap&& _headers): HttpRequest(QObject* _parent, QUrl&& _url, QString&& _content, QVariantMap&& _headers):
QObject(_parent), m_url(_url), m_content(_content), m_headers(_headers) QObject(_parent), m_url(std::move(_url)), m_content(std::move(_content)), m_headers(std::move(_headers))
{ {
} }

4
test/TestHelper.cpp

@ -199,10 +199,10 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state, stateOptio
stateOptions.m_bHasCode = true; stateOptions.m_bHasCode = true;
} }
if (code.size()) if (!code.empty())
{ {
_state.m_cache[address] = Account(balance, Account::ContractConception); _state.m_cache[address] = Account(balance, Account::ContractConception);
_state.m_cache[address].setCode(code); _state.m_cache[address].setCode(std::move(code));
} }
else else
_state.m_cache[address] = Account(balance, Account::NormalCreation); _state.m_cache[address] = Account(balance, Account::NormalCreation);

Loading…
Cancel
Save