From e3f90565d8f623537072d84316d476343c2b06ad Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 27 Jul 2017 16:40:01 +0200 Subject: Avoid some Json copy operations. --- libsolidity/ast/ASTJsonConverter.cpp | 31 ++++++++++++------------------- libsolidity/ast/ASTJsonConverter.h | 13 +++++++++++-- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 3f16db23..fdec8945 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -15,8 +15,7 @@ along with solidity. If not, see . */ /** - * @author Lefteris - * @date 2015 + * @date 2017 * Converts the AST into json format */ @@ -81,28 +80,22 @@ void ASTJsonConverter::setJsonNode( (_nodeType == "InlineAssembly") || (_nodeType == "Throw") ) - { - Json::Value children(Json::arrayValue); - m_currentValue["children"] = children; - } + m_currentValue["children"] = Json::arrayValue; for (auto& e: _attributes) { - if ( - (!e.second.isNull()) && - ( - (e.second.isObject() && e.second.isMember("name")) || - (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.isNull()) && ( + (e.second.isObject() && e.second.isMember("name")) || + (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()) - m_currentValue["children"].append(std::move(e.second)); + appendMove(m_currentValue["children"], std::move(e.second)); if (e.second.isArray()) for (auto& child: e.second) if (!child.isNull()) - m_currentValue["children"].append(std::move(child)); + appendMove(m_currentValue["children"], std::move(child)); } else { @@ -147,7 +140,7 @@ Json::Value ASTJsonConverter::typePointerToJson(std::shared_ptr Json::Value toJson(std::vector> const& _nodes) { Json::Value ret(Json::arrayValue); 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; } bool visit(SourceUnit const& _node) override; @@ -155,6 +158,12 @@ private: std::vector> &_attributes, 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_inEvent = false; ///< whether we are currently inside an event or not Json::Value m_currentValue; -- cgit From 4b56829ac3dc28ea9ca6945fee22963149bcc2bd Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 17 Aug 2017 02:13:16 +0100 Subject: Create children node in ASTJsonConverter when neccesary --- libsolidity/ast/ASTJsonConverter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index fdec8945..6d541803 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -91,11 +91,19 @@ void ASTJsonConverter::setJsonNode( )) { if (e.second.isObject()) + { + if (!m_currentValue["children"].isArray()) + m_currentValue["children"] = Json::arrayValue; appendMove(m_currentValue["children"], std::move(e.second)); + } if (e.second.isArray()) for (auto& child: e.second) if (!child.isNull()) + { + if (!m_currentValue["children"].isArray()) + m_currentValue["children"] = Json::arrayValue; appendMove(m_currentValue["children"], std::move(child)); + } } else { -- cgit