- enhancement: reduce memory usage when deciding file type

This commit is contained in:
Roy Qu 2022-10-24 12:51:50 +08:00
parent fcb64a69af
commit 0d45cca2a5
3 changed files with 21 additions and 19 deletions

View File

@ -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

View File

@ -2550,21 +2550,21 @@ bool Editor::handleCodeCompletion(QChar key)
void Editor::initParser()
{
mParser=nullptr;
// mParser = std::make_shared<CppParser>();
// 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<CppParser>();
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)

View File

@ -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;
}