From c4d544f0b21ea017f7e0dafcf66509420dd59921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 16 Feb 2021 02:24:31 -0300 Subject: [PATCH] TextDocument: Fixed a crash on remove function. Faster Node::childsCloseAll. ecode: Added basic Solidity support. And some minor changes. --- bin/assets/linters/linters.json | 2 +- include/eepp/scene/node.hpp | 5 +- src/eepp/scene/node.cpp | 15 ++-- src/eepp/scene/scenenode.cpp | 13 +++- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 86 +++++++++++++++++++-- src/eepp/ui/doc/textdocument.cpp | 4 +- src/eepp/ui/uiscenenode.cpp | 4 +- src/eepp/ui/uiwidget.cpp | 2 - src/tests/ui_perf_test/ui_perf_test.cpp | 18 ++++- 9 files changed, 122 insertions(+), 27 deletions(-) diff --git a/bin/assets/linters/linters.json b/bin/assets/linters/linters.json index 127dc84fa..a17b1596c 100644 --- a/bin/assets/linters/linters.json +++ b/bin/assets/linters/linters.json @@ -20,7 +20,7 @@ "file_patterns": ["%.py$"], "warning_pattern": "[^:]:(%d+):(%d+):%s([%w]+:%s[^\n]*)", "column_starts_at_zero": true, - "command": "pylint --score=n $FILENAME" + "command": "pylint --disable=C0114,C0115,C0116,C0103 --score=n $FILENAME" }, { "file_patterns": ["%.sh$"], diff --git a/include/eepp/scene/node.hpp b/include/eepp/scene/node.hpp index 1ca86ca92..7f76d2d1b 100644 --- a/include/eepp/scene/node.hpp +++ b/include/eepp/scene/node.hpp @@ -62,7 +62,8 @@ enum NodeFlags { NODE_FLAG_LAYOUT = ( 1 << 26 ), NODE_FLAG_LOADING = ( 1 << 27 ), - NODE_FLAG_FREE_USE = ( 1 << 28 ) + NODE_FLAG_CLOSING_CHILDREN = ( 1 << 28 ), + NODE_FLAG_FREE_USE = ( 1 << 29 ) }; class EE_API Node : public Transformable { @@ -391,6 +392,8 @@ class EE_API Node : public Transformable { bool isClosing() const; + bool isClosingChildren() const; + virtual Node* overFind( const Vector2f& Point ); /** This removes the node from its parent. Never use this unless you know what you are doing. */ diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index d5eb3c9c9..dee6d5118 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -696,12 +696,13 @@ void Node::childRemove( Node* node ) { } void Node::childsCloseAll() { - Node* ChildLoop = mChild; - - while ( NULL != ChildLoop ) { - ChildLoop->close(); - ChildLoop = ChildLoop->mNext; + Node* childLoop = mChild; + writeNodeFlag( NODE_FLAG_CLOSING_CHILDREN, 1 ); + while ( NULL != childLoop ) { + childLoop->close(); + childLoop = childLoop->mNext; } + writeNodeFlag( NODE_FLAG_CLOSING_CHILDREN, 0 ); } std::string Node::getId() const { @@ -723,6 +724,10 @@ bool Node::isClosing() const { return 0 != ( mNodeFlags & NODE_FLAG_CLOSE ); } +bool Node::isClosingChildren() const { + return 0 != ( mNodeFlags & NODE_FLAG_CLOSING_CHILDREN ); +} + const String::HashType& Node::getIdHash() const { return mIdHash; } diff --git a/src/eepp/scene/scenenode.cpp b/src/eepp/scene/scenenode.cpp index 2fa38fcab..bbb44504b 100644 --- a/src/eepp/scene/scenenode.cpp +++ b/src/eepp/scene/scenenode.cpp @@ -181,8 +181,15 @@ void SceneNode::addToCloseQueue( Node* node ) { if ( mCloseList.count( node ) > 0 ) return; + // If the parent is closing all his children, we skip all the verifications and add it to the + // close list + if ( node->getParent() && node->getParent()->isClosingChildren() ) { + mCloseList.insert( node ); + return; + } + for ( auto& closeNode : mCloseList ) { - if ( NULL != closeNode && closeNode->isParentOf( node ) ) { + if ( closeNode && closeNode->isParentOf( node ) ) { // If a parent will be removed, means that the node // that we are trying to queue will be removed by the father // so we skip it @@ -195,13 +202,11 @@ void SceneNode::addToCloseQueue( Node* node ) { for ( auto it = mCloseList.begin(); it != mCloseList.end(); ++it ) { itNode = *it; - if ( NULL != itNode && node->isParentOf( itNode ) ) { + if ( NULL == itNode || node->isParentOf( itNode ) ) { // if the node added is parent of another node already added, // we remove the already added node because it will be deleted // by its parent itEraseList.push_back( it ); - } else if ( NULL == itNode ) { - itEraseList.push_back( it ); } } diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index d30f9d52b..6a50ed003 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -218,7 +218,7 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { // sh - bash add( { "Bash", - { "%.sh$", "%.bash$" }, + { "%.sh$", "%.bash$", "%.bashrc$", "%.bash_profile$" }, { { { "#.*\n" }, "comment" }, { { "[[\\.]]" }, "normal" }, @@ -1670,8 +1670,8 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { auto prepareBatchSymbols = []( std::unordered_map> table ) -> std::unordered_map { std::unordered_map symbols; - for ( auto el : table ) { - for ( auto it : el.second ) { + for ( auto& el : table ) { + for ( const auto& it : el.second ) { symbols[String::toLower( it )] = el.first; symbols[String::toUpper( it )] = el.first; } @@ -1996,6 +1996,82 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { { "Optional", "keyword2" }, }, "//" } ); + + add( { "Solidity", + { "%.sol$" }, + { + { { "//.-\n" }, "comment" }, + { { "/%*", "%*/" }, "comment" }, + { { "\"\"\"", "\"\"\"" }, "string" }, + { { "\"", "\"", "\\" }, "string" }, + { { "-?0x%x+" }, "number" }, + { { "-?%d+[%d%.eE]*f?" }, "number" }, + { { "-?%.?%d+f?" }, "number" }, + { { "[%+%-=/%*%^%%<>!~|&]" }, "operator" }, + { { "[%a_][%w_]*%f[(]" }, "function" }, + { { "[%a_][%w_]*" }, "symbol" }, + }, + { + { "if", "keyword" }, { "else", "keyword" }, + { "for", "keyword" }, { "while", "keyword" }, + { "do", "keyword" }, { "break", "keyword" }, + { "continue", "keyword" }, { "throw", "keyword" }, + { "returns", "keyword" }, { "return", "keyword" }, + { "function", "keyword" }, { "private", "keyword2" }, + { "public", "keyword2" }, { "internal", "keyword2" }, + { "external", "keyword2" }, { "constant", "keyword2" }, + { "immutable", "keyword2" }, { "pure", "keyword2" }, + { "view", "keyword2" }, { "payable", "keyword2" }, + { "nonpayable", "keyword2" }, { "inherited", "keyword2" }, + { "indexed", "keyword2" }, { "storage", "keyword2" }, + { "memory", "keyword2" }, { "virtual", "keyword2" }, + { "calldata", "keyword2" }, { "override", "keyword2" }, + { "abstract", "keyword" }, { "library", "keyword" }, + { "enum", "keyword" }, { "constructor", "keyword" }, + { "event", "keyword" }, { "modifier", "keyword" }, + { "assembly", "keyword" }, { "let", "keyword" }, + { "msg", "keyword2" }, { "block", "keyword2" }, + { "tx", "keyword2" }, { "now", "keyword2" }, + { "this", "keyword2" }, { "super", "keyword2" }, + { "require", "keyword" }, { "assert", "keyword2" }, + { "revert", "keyword2" }, { "selfdestruct", "keyword2" }, + { "suicide", "keyword2" }, { "addmod", "keyword2" }, + { "mulmod", "keyword2" }, { "keccak256", "keyword2" }, + { "sha256", "keyword2" }, { "sha3", "keyword2" }, + { "ripemd160", "keyword2" }, { "ecrecover", "keyword2" }, + { "blockhash", "keyword2" }, { "gasleft", "keyword2" }, + { "contract", "keyword" }, { "interface", "keyword" }, + { "modifier", "keyword" }, { "mapping", "keyword2" }, + { "address", "keyword2" }, { "string", "keyword2" }, + { "byte", "keyword2" }, { "bytes", "keyword2" }, + { "bytes1", "keyword2" }, { "bytes2", "keyword2" }, + { "bytes3", "keyword2" }, { "bytes4", "keyword2" }, + { "bytes5", "keyword2" }, { "bytes6", "keyword2" }, + { "bytes7", "keyword2" }, { "bytes8", "keyword2" }, + { "bytes9", "keyword2" }, { "bytes10", "keyword2" }, + { "bytes11", "keyword2" }, { "bytes12", "keyword2" }, + { "bytes13", "keyword2" }, { "bytes14", "keyword2" }, + { "bytes15", "keyword2" }, { "bytes16", "keyword2" }, + { "bytes17", "keyword2" }, { "bytes18", "keyword2" }, + { "bytes19", "keyword2" }, { "bytes20", "keyword2" }, + { "bytes21", "keyword2" }, { "bytes22", "keyword2" }, + { "bytes23", "keyword2" }, { "bytes24", "keyword2" }, + { "bytes25", "keyword2" }, { "bytes26", "keyword2" }, + { "bytes27", "keyword2" }, { "bytes28", "keyword2" }, + { "bytes29", "keyword2" }, { "bytes30", "keyword2" }, + { "bytes31", "keyword2" }, { "bytes32", "keyword2" }, + { "int", "keyword2" }, { "int8", "keyword2" }, + { "int16", "keyword2" }, { "int32", "keyword2" }, + { "int64", "keyword2" }, { "int128", "keyword2" }, + { "int256", "keyword2" }, { "uint", "keyword2" }, + { "uint8", "keyword2" }, { "uint16", "keyword2" }, + { "uint32", "keyword2" }, { "uint64", "keyword2" }, + { "uint128", "keyword2" }, { "uint256", "keyword2" }, + { "bool", "keyword2" }, { "hash", "keyword2" }, + { "pragma", "keyword2" }, { "using", "keyword" }, + { "is", "keyword" }, { "new", "keyword" }, + { "delete", "keyword" }, { "emit", "keyword" }, + } } ); } SyntaxDefinition& SyntaxDefinitionManager::add( SyntaxDefinition&& syntaxStyle ) { @@ -2052,7 +2128,7 @@ SyntaxDefinitionManager::getStyleByExtension( const std::string& filePath ) cons if ( !extension.empty() ) { for ( auto style = mStyles.rbegin(); style != mStyles.rend(); ++style ) { - for ( auto ext : style->getFiles() ) { + for ( const auto& ext : style->getFiles() ) { if ( String::startsWith( ext, "%." ) || String::endsWith( ext, "$" ) ) { LuaPattern words( ext ); int start, end; @@ -2072,7 +2148,7 @@ const SyntaxDefinition& SyntaxDefinitionManager::getStyleByHeader( const std::string& header ) const { if ( !header.empty() ) { for ( auto style = mStyles.rbegin(); style != mStyles.rend(); ++style ) { - for ( auto hdr : style->getHeaders() ) { + for ( const auto& hdr : style->getHeaders() ) { LuaPattern words( hdr ); int start, end; if ( words.find( header, start, end ) ) { diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index ccda682a4..9af65bb11 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -561,7 +561,7 @@ void TextDocument::remove( TextRange range, UndoStackContainer& undoStack, const } else { auto beforeSelection = line.substr( 0, range.start().column() ); auto afterSelection = - !line.empty() + !line.empty() && range.end().column() < (Int64)line.size() ? line.substr( range.end().column(), line.length() - range.end().column() ) : ""; @@ -578,7 +578,7 @@ void TextDocument::remove( TextRange range, UndoStackContainer& undoStack, const TextDocumentLine& firstLine = line( range.start().line() ); TextDocumentLine& secondLine = line( range.end().line() ); auto beforeSelection = firstLine.substr( 0, range.start().column() ); - auto afterSelection = !secondLine.empty() + auto afterSelection = !secondLine.empty() && range.end().column() < (Int64)secondLine.size() ? secondLine.substr( range.end().column(), secondLine.length() - range.end().column() ) : ""; diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 3d4bdd9e5..f3e78668d 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -534,9 +534,7 @@ void UISceneNode::invalidateStyle( UIWidget* node ) { for ( auto it = mDirtyStyle.begin(); it != mDirtyStyle.end(); ++it ) { itNode = *it; - if ( NULL != itNode && node->isParentOf( itNode ) ) { - itEraseList.push_back( it ); - } else if ( NULL == itNode ) { + if ( NULL == itNode || node->isParentOf( itNode ) ) { itEraseList.push_back( it ); } } diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 17c06f905..8ed60ebfb 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -51,8 +51,6 @@ UIWidget::UIWidget( const std::string& tag ) : mUISceneNode->invalidateStyle( this ); mUISceneNode->invalidateStyleState( this, true ); } - - updateAnchorsDistances(); } UIWidget::UIWidget() : UIWidget( "widget" ) {} diff --git a/src/tests/ui_perf_test/ui_perf_test.cpp b/src/tests/ui_perf_test/ui_perf_test.cpp index 090754b8c..f9c0bb2a8 100644 --- a/src/tests/ui_perf_test/ui_perf_test.cpp +++ b/src/tests/ui_perf_test/ui_perf_test.cpp @@ -6,7 +6,7 @@ class TestModel : public Model { public: struct NodeT { std::vector children; - NodeT* parent{nullptr}; + NodeT* parent{ nullptr }; ModelIndex index( const TestModel& model, int column ) const { if ( !parent ) @@ -217,7 +217,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { widgetTree->setExpanderIconSize( PixelDensity::dpToPx( 20 ) ); widgetTree->setModel( WidgetTreeModel::New( uiSceneNode ) ); - /* ListBox test */ /* + /* ListBox test *//* std::vector strings; for ( size_t i = 0; i < 10000; i++ ) strings.emplace_back( String::format( @@ -228,7 +228,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { lbox->setParent( vlay ); std::cout << "Time setParent: " << clock.getElapsed().asMilliseconds() << " ms" << std::endl; - lbox->setLayoutMargin( Rect( 4, 4, 4, 4 ) ); + lbox->setLayoutMargin( Rectf( 4, 4, 4, 4 ) ); std::cout << "Time setLayoutMargin: " << clock.getElapsed().asMilliseconds() << " ms" << std::endl; lbox->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent ); @@ -247,12 +247,22 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { /* Create Widget test */ Clock total; /*for ( size_t i = 0; i < 10000; i++ ) { - auto* widget = UINode::New(); + UINode::New(); } std::cout << "Time UINode total: " << total.getElapsedTime().asMilliseconds() << " ms" << std::endl; uiSceneNode->getRoot()->childsCloseAll(); + + total.restart(); + for ( size_t i = 0; i < 10000; i++ ) { + UIWidget::New(); + } + std::cout << "Time UIWidget total: " << total.getElapsedTime().asMilliseconds() << " ms" + << std::endl; + + uiSceneNode->getRoot()->childsCloseAll(); + SceneManager::instance()->update();*/ /*total.restart();