mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2656 from ethereum/performance1
Avoid some Json copy operations.
This commit is contained in:
commit
c5f11d938f
@ -233,7 +233,7 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
|
|||||||
{
|
{
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
|
||||||
Json::Value collection(Json::arrayValue);
|
Json::Value& collection = root[".code"] = Json::arrayValue;
|
||||||
for (AssemblyItem const& i: m_items)
|
for (AssemblyItem const& i: m_items)
|
||||||
{
|
{
|
||||||
switch (i.type())
|
switch (i.type())
|
||||||
@ -289,11 +289,9 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root[".code"] = collection;
|
|
||||||
|
|
||||||
if (!m_data.empty() || !m_subs.empty())
|
if (!m_data.empty() || !m_subs.empty())
|
||||||
{
|
{
|
||||||
Json::Value data;
|
Json::Value& data = root[".data"] = Json::objectValue;
|
||||||
for (auto const& i: m_data)
|
for (auto const& i: m_data)
|
||||||
if (u256(i.first) >= m_subs.size())
|
if (u256(i.first) >= m_subs.size())
|
||||||
data[toStringInHex((u256)i.first)] = toHex(i.second);
|
data[toStringInHex((u256)i.first)] = toHex(i.second);
|
||||||
@ -304,7 +302,6 @@ Json::Value Assembly::streamAsmJson(ostream& _out, StringMap const& _sourceCodes
|
|||||||
hexStr << hex << i;
|
hexStr << hex << i;
|
||||||
data[hexStr.str()] = m_subs[i]->stream(_out, "", _sourceCodes, true);
|
data[hexStr.str()] = m_subs[i]->stream(_out, "", _sourceCodes, true);
|
||||||
}
|
}
|
||||||
root[".data"] = data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_auxiliaryData.size() > 0)
|
if (m_auxiliaryData.size() > 0)
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @author Lefteris <lefteris@ethdev.com>
|
* @date 2017
|
||||||
* @date 2015
|
|
||||||
* Converts the AST into json format
|
* Converts the AST into json format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -81,28 +80,30 @@ void ASTJsonConverter::setJsonNode(
|
|||||||
(_nodeType == "InlineAssembly") ||
|
(_nodeType == "InlineAssembly") ||
|
||||||
(_nodeType == "Throw")
|
(_nodeType == "Throw")
|
||||||
)
|
)
|
||||||
{
|
m_currentValue["children"] = Json::arrayValue;
|
||||||
Json::Value children(Json::arrayValue);
|
|
||||||
m_currentValue["children"] = children;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& e: _attributes)
|
for (auto& e: _attributes)
|
||||||
{
|
{
|
||||||
if (
|
if ((!e.second.isNull()) && (
|
||||||
(!e.second.isNull()) &&
|
(e.second.isObject() && e.second.isMember("name")) ||
|
||||||
(
|
(e.second.isArray() && e.second[0].isObject() && e.second[0].isMember("name")) ||
|
||||||
(e.second.isObject() && e.second.isMember("name")) ||
|
(e.first == "declarations") // (in the case (_,x)= ... there's a nullpointer at [0]
|
||||||
(e.second.isArray() && e.second[0].isObject() && e.second[0].isMember("name")) ||
|
))
|
||||||
(e.first == "declarations") // (in the case (_,x)= ... there's a nullpointer at [0]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (e.second.isObject())
|
if (e.second.isObject())
|
||||||
m_currentValue["children"].append(std::move(e.second));
|
{
|
||||||
|
if (!m_currentValue["children"].isArray())
|
||||||
|
m_currentValue["children"] = Json::arrayValue;
|
||||||
|
appendMove(m_currentValue["children"], std::move(e.second));
|
||||||
|
}
|
||||||
if (e.second.isArray())
|
if (e.second.isArray())
|
||||||
for (auto& child: e.second)
|
for (auto& child: e.second)
|
||||||
if (!child.isNull())
|
if (!child.isNull())
|
||||||
m_currentValue["children"].append(std::move(child));
|
{
|
||||||
|
if (!m_currentValue["children"].isArray())
|
||||||
|
m_currentValue["children"] = Json::arrayValue;
|
||||||
|
appendMove(m_currentValue["children"], std::move(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -147,7 +148,7 @@ Json::Value ASTJsonConverter::typePointerToJson(std::shared_ptr<std::vector<Type
|
|||||||
{
|
{
|
||||||
Json::Value arguments(Json::arrayValue);
|
Json::Value arguments(Json::arrayValue);
|
||||||
for (auto const& tp: *_tps)
|
for (auto const& tp: *_tps)
|
||||||
arguments.append(typePointerToJson(tp));
|
appendMove(arguments, typePointerToJson(tp));
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -186,7 +187,7 @@ void ASTJsonConverter::print(ostream& _stream, ASTNode const& _node)
|
|||||||
_stream << toJson(_node);
|
_stream << toJson(_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value ASTJsonConverter::toJson(ASTNode const& _node)
|
Json::Value&& ASTJsonConverter::toJson(ASTNode const& _node)
|
||||||
{
|
{
|
||||||
_node.accept(*this);
|
_node.accept(*this);
|
||||||
return std::move(m_currentValue);
|
return std::move(m_currentValue);
|
||||||
@ -543,7 +544,7 @@ bool ASTJsonConverter::visit(VariableDeclarationStatement const& _node)
|
|||||||
{
|
{
|
||||||
Json::Value varDecs(Json::arrayValue);
|
Json::Value varDecs(Json::arrayValue);
|
||||||
for (auto const& v: _node.annotation().assignments)
|
for (auto const& v: _node.annotation().assignments)
|
||||||
varDecs.append(idOrNull(v));
|
appendMove(varDecs, idOrNull(v));
|
||||||
setJsonNode(_node, "VariableDeclarationStatement", {
|
setJsonNode(_node, "VariableDeclarationStatement", {
|
||||||
make_pair("assignments", std::move(varDecs)),
|
make_pair("assignments", std::move(varDecs)),
|
||||||
make_pair("declarations", toJson(_node.declarations())),
|
make_pair("declarations", toJson(_node.declarations())),
|
||||||
|
@ -49,13 +49,16 @@ public:
|
|||||||
);
|
);
|
||||||
/// Output the json representation of the AST to _stream.
|
/// Output the json representation of the AST to _stream.
|
||||||
void print(std::ostream& _stream, ASTNode const& _node);
|
void print(std::ostream& _stream, ASTNode const& _node);
|
||||||
Json::Value toJson(ASTNode const& _node);
|
Json::Value&& toJson(ASTNode const& _node);
|
||||||
template <class T>
|
template <class T>
|
||||||
Json::Value toJson(std::vector<ASTPointer<T>> const& _nodes)
|
Json::Value toJson(std::vector<ASTPointer<T>> const& _nodes)
|
||||||
{
|
{
|
||||||
Json::Value ret(Json::arrayValue);
|
Json::Value ret(Json::arrayValue);
|
||||||
for (auto const& n: _nodes)
|
for (auto const& n: _nodes)
|
||||||
ret.append(n ? toJson(*n) : Json::nullValue);
|
if (n)
|
||||||
|
appendMove(ret, toJson(*n));
|
||||||
|
else
|
||||||
|
ret.append(Json::nullValue);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
bool visit(SourceUnit const& _node) override;
|
bool visit(SourceUnit const& _node) override;
|
||||||
@ -154,6 +157,12 @@ private:
|
|||||||
std::vector<std::pair<std::string, Json::Value>> &_attributes,
|
std::vector<std::pair<std::string, Json::Value>> &_attributes,
|
||||||
ExpressionAnnotation const& _annotation
|
ExpressionAnnotation const& _annotation
|
||||||
);
|
);
|
||||||
|
static void appendMove(Json::Value& _array, Json::Value&& _value)
|
||||||
|
{
|
||||||
|
solAssert(_array.isArray(), "");
|
||||||
|
_array.append(std::move(_value));
|
||||||
|
}
|
||||||
|
|
||||||
bool m_legacy = false; ///< if true, use legacy format
|
bool m_legacy = false; ///< if true, use legacy format
|
||||||
bool m_inEvent = false; ///< whether we are currently inside an event or not
|
bool m_inEvent = false; ///< whether we are currently inside an event or not
|
||||||
Json::Value m_currentValue;
|
Json::Value m_currentValue;
|
||||||
|
@ -851,7 +851,7 @@ void CommandLineInterface::handleCombinedJSON()
|
|||||||
output[g_strContracts] = Json::Value(Json::objectValue);
|
output[g_strContracts] = Json::Value(Json::objectValue);
|
||||||
for (string const& contractName: contracts)
|
for (string const& contractName: contracts)
|
||||||
{
|
{
|
||||||
Json::Value contractData(Json::objectValue);
|
Json::Value& contractData = output[g_strContracts][contractName] = Json::objectValue;
|
||||||
if (requests.count(g_strAbi))
|
if (requests.count(g_strAbi))
|
||||||
contractData[g_strAbi] = dev::jsonCompactPrint(m_compiler->contractABI(contractName));
|
contractData[g_strAbi] = dev::jsonCompactPrint(m_compiler->contractABI(contractName));
|
||||||
if (requests.count("metadata"))
|
if (requests.count("metadata"))
|
||||||
@ -885,7 +885,6 @@ void CommandLineInterface::handleCombinedJSON()
|
|||||||
contractData[g_strNatspecDev] = dev::jsonCompactPrint(m_compiler->natspecDev(contractName));
|
contractData[g_strNatspecDev] = dev::jsonCompactPrint(m_compiler->natspecDev(contractName));
|
||||||
if (requests.count(g_strNatspecUser))
|
if (requests.count(g_strNatspecUser))
|
||||||
contractData[g_strNatspecUser] = dev::jsonCompactPrint(m_compiler->natspecUser(contractName));
|
contractData[g_strNatspecUser] = dev::jsonCompactPrint(m_compiler->natspecUser(contractName));
|
||||||
output[g_strContracts][contractName] = contractData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool needsSourceList = requests.count(g_strAst) || requests.count(g_strSrcMap) || requests.count(g_strSrcMapRuntime);
|
bool needsSourceList = requests.count(g_strAst) || requests.count(g_strSrcMap) || requests.count(g_strSrcMapRuntime);
|
||||||
|
Loading…
Reference in New Issue
Block a user