aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-05-23 22:55:58 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-06-25 23:17:18 +0800
commita55e8c93ce1c3982ec224eacbb56cca243acb15e (patch)
tree8205e25a25d22163c177908cdf1fe18e64639a04 /libsolidity
parent86a720b96a45ce1b59ab1038e7bb465f9a566189 (diff)
downloaddexon-solidity-a55e8c93ce1c3982ec224eacbb56cca243acb15e.tar.gz
dexon-solidity-a55e8c93ce1c3982ec224eacbb56cca243acb15e.tar.zst
dexon-solidity-a55e8c93ce1c3982ec224eacbb56cca243acb15e.zip
Save double encode call for sha3.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp
index e579264e..ecbd0243 100644
--- a/libsolidity/codegen/ExpressionCompiler.cpp
+++ b/libsolidity/codegen/ExpressionCompiler.cpp
@@ -699,16 +699,24 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
}
case FunctionType::Kind::SHA3:
{
- TypePointers argumentTypes;
- for (auto const& arg: arguments)
+ solAssert(arguments.size() == 1, "");
+ solAssert(!function.padArguments(), "");
+ TypePointer const& argType = arguments.front()->annotation().type;
+ solAssert(argType, "");
+ arguments.front()->accept(*this);
+ // Optimization: If type is bytes or string, then do not encode,
+ // but directly compute keccak256 on memory.
+ if (*argType == ArrayType(DataLocation::Memory) || *argType == ArrayType(DataLocation::Memory, true))
{
- arg->accept(*this);
- argumentTypes.push_back(arg->annotation().type);
+ ArrayUtils(m_context).retrieveLength(ArrayType(DataLocation::Memory));
+ m_context << Instruction::SWAP1 << u256(0x20) << Instruction::ADD;
+ }
+ else
+ {
+ utils().fetchFreeMemoryPointer();
+ utils().packedEncode({argType}, TypePointers());
+ utils().toSizeAfterFreeMemoryPointer();
}
- utils().fetchFreeMemoryPointer();
- solAssert(!function.padArguments(), "");
- utils().packedEncode(argumentTypes, TypePointers());
- utils().toSizeAfterFreeMemoryPointer();
m_context << Instruction::KECCAK256;
break;
}