From 0d45cca2a5cb94ad1aa7b8dec5eeb0cfbedb60b0 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 24 Oct 2022 12:51:50 +0800 Subject: [PATCH] - enhancement: reduce memory usage when deciding file type --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 32 +++++++++++++++++--------------- RedPandaIDE/utils.cpp | 7 +++---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/NEWS.md b/NEWS.md index a87a6b43..4f0bf060 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ Red Panda C++ Version 2.0 - enhancement: Weither double click on the class browser should goto definition/declaration, depends on the current cursor position - enhancement: keep current position in the class browser after contents modified - fix: "." and ".." in included header paths not correctly handled + - reduce memory usage when deciding file types Red Panda C++ Version 1.5 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 354f1f42..12265b7f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2550,21 +2550,21 @@ bool Editor::handleCodeCompletion(QChar key) void Editor::initParser() { - mParser=nullptr; -// mParser = std::make_shared(); -// if (mUseCppSyntax) { -// mParser->setLanguage(ParserLanguage::CPlusPlus); -// } else { -// mParser->setLanguage(ParserLanguage::C); -// } -// mParser->setOnGetFileStream( -// std::bind( -// &EditorList::getContentFromOpenedEditor,pMainWindow->editorList(), -// std::placeholders::_1, std::placeholders::_2)); -// resetCppParser(mParser); -// mParser->setEnabled( -// pSettings->codeCompletion().enabled() && -// (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)); +// mParser=nullptr; + mParser = std::make_shared(); + if (mUseCppSyntax) { + mParser->setLanguage(ParserLanguage::CPlusPlus); + } else { + mParser->setLanguage(ParserLanguage::C); + } + mParser->setOnGetFileStream( + std::bind( + &EditorList::getContentFromOpenedEditor,pMainWindow->editorList(), + std::placeholders::_1, std::placeholders::_2)); + resetCppParser(mParser); + mParser->setEnabled( + pSettings->codeCompletion().enabled() && + (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)); } Editor::QuoteStatus Editor::getQuoteStatus() @@ -3458,6 +3458,8 @@ QString Editor::getFileHint(const QString &s, bool fromNext) QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/, int line) { + if (!mParser) + return ""; // This piece of code changes the parser database, possibly making hints and code completion invalid... QString result; // Exit early, don't bother creating a stream (which is slow) diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index cc9f446c..8b9be845 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -140,10 +140,9 @@ FileType getFileType(const QString &filename) if (filename.endsWith(".dat",PATH_SENSITIVITY)) { return FileType::Text; } - QMimeDatabase db; - QMimeType mimeType=db.mimeTypeForFile(filename); - if (mimeType.isValid() && mimeType.name().startsWith("text/")) { - return FileType::Text; + QFileInfo info(filename); + if (info.suffix().isEmpty()) { + return FileType::Other; } return FileType::Other; }