mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Refactor] Add AssemblyItem as param to copyRoutine
This commit is contained in:
parent
43821d7fd1
commit
742fef401e
@ -153,21 +153,17 @@ AssemblyItems CodeCopyMethod::execute(Assembly& _assembly) const
|
|||||||
{
|
{
|
||||||
bytes data = toBigEndian(m_value);
|
bytes data = toBigEndian(m_value);
|
||||||
assertThrow(data.size() == 32, OptimizerException, "Invalid number encoding.");
|
assertThrow(data.size() == 32, OptimizerException, "Invalid number encoding.");
|
||||||
AssemblyItems actualCopyRoutine = copyRoutine();
|
AssemblyItem newPushData = _assembly.newData(data);
|
||||||
if (m_params.evmVersion.hasPush0())
|
return copyRoutine(&newPushData);
|
||||||
actualCopyRoutine[3] = _assembly.newData(data);
|
|
||||||
else
|
|
||||||
actualCopyRoutine[4] = _assembly.newData(data);
|
|
||||||
return actualCopyRoutine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AssemblyItems const& CodeCopyMethod::copyRoutine() const
|
AssemblyItems CodeCopyMethod::copyRoutine(AssemblyItem* _pushData) const
|
||||||
{
|
{
|
||||||
// PUSH0 is cheaper than PUSHn/DUP/SWAP.
|
// PUSH0 is cheaper than PUSHn/DUP/SWAP.
|
||||||
if (m_params.evmVersion.hasPush0())
|
if (m_params.evmVersion.hasPush0())
|
||||||
{
|
{
|
||||||
// This costs ~29 gas.
|
// This costs ~29 gas.
|
||||||
AssemblyItems static copyRoutine{
|
AssemblyItems copyRoutine{
|
||||||
// back up memory
|
// back up memory
|
||||||
// mload(0)
|
// mload(0)
|
||||||
u256(0),
|
u256(0),
|
||||||
@ -175,7 +171,7 @@ AssemblyItems const& CodeCopyMethod::copyRoutine() const
|
|||||||
|
|
||||||
// codecopy(0, <offset>, 32)
|
// codecopy(0, <offset>, 32)
|
||||||
u256(32),
|
u256(32),
|
||||||
AssemblyItem(PushData, u256(1) << 16), // replaced above in actualCopyRoutine[3]
|
(_pushData ? *_pushData : AssemblyItem(PushData, u256(1) << 16)),
|
||||||
u256(0),
|
u256(0),
|
||||||
Instruction::CODECOPY,
|
Instruction::CODECOPY,
|
||||||
|
|
||||||
@ -194,7 +190,7 @@ AssemblyItems const& CodeCopyMethod::copyRoutine() const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// This costs ~33 gas.
|
// This costs ~33 gas.
|
||||||
AssemblyItems static copyRoutine{
|
AssemblyItems copyRoutine{
|
||||||
// constant to be reused 3+ times
|
// constant to be reused 3+ times
|
||||||
u256(0),
|
u256(0),
|
||||||
|
|
||||||
@ -205,7 +201,7 @@ AssemblyItems const& CodeCopyMethod::copyRoutine() const
|
|||||||
|
|
||||||
// codecopy(0, <offset>, 32)
|
// codecopy(0, <offset>, 32)
|
||||||
u256(32),
|
u256(32),
|
||||||
AssemblyItem(PushData, u256(1) << 16), // replaced above in actualCopyRoutine[4]
|
(_pushData ? *_pushData : AssemblyItem(PushData, u256(1) << 16)),
|
||||||
Instruction::DUP4,
|
Instruction::DUP4,
|
||||||
Instruction::CODECOPY,
|
Instruction::CODECOPY,
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public:
|
|||||||
AssemblyItems execute(Assembly& _assembly) const override;
|
AssemblyItems execute(Assembly& _assembly) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AssemblyItems const& copyRoutine() const;
|
AssemblyItems copyRoutine(AssemblyItem* _pushData = nullptr) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user