From 13d81b11341693b1d8cd80f1bad5e1cd368f01e2 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 27 Oct 2023 20:16:44 +0800 Subject: [PATCH] reduce memory usage --- RedPandaIDE/parser/cppparser.cpp | 18 ++++++++++++++--- RedPandaIDE/parser/cpppreprocessor.cpp | 28 +++++++++++++++----------- RedPandaIDE/parser/parserutils.h | 13 ++++++------ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 8c55d992..319dacfe 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -1337,6 +1337,7 @@ PStatement CppParser::addStatement(const PStatement& parent, newType += newCommand.front(); newCommand.remove(0,1); // remove first } + newCommand.squeeze(); // if (newCommand.startsWith("::") && parent && kind!=StatementKind::skBlock ) { // qDebug()<fullName; // } @@ -1398,6 +1399,13 @@ PStatement CppParser::addStatement(const PStatement& parent, else result->fullName = getFullStatementName(newCommand, parent); result->usageCount = -1; + + result->args.squeeze(); + result->noNameArgs.squeeze(); + result->value.squeeze(); + result->type.squeeze(); + //result->fullName.squeeze(); + //result->command.squeeze(); mStatementList.add(result); if (result->kind == StatementKind::skNamespace) { PStatementList namespaceList = mNamespaces.value(result->fullName,PStatementList()); @@ -1417,6 +1425,8 @@ PStatement CppParser::addStatement(const PStatement& parent, // if (result->command=="sync_with_stdio") { // qDebug()<fullName<isStatic()<<(int)result->accessibility; // } + + return result; } @@ -2476,9 +2486,11 @@ QString CppParser::getFullStatementName(const QString &command, const PStatement PStatement scopeStatement=parent; while (scopeStatement && !isNamedScope(scopeStatement->kind)) scopeStatement = scopeStatement->parentScope.lock(); - if (scopeStatement) - return scopeStatement->fullName + "::" + command; - else + if (scopeStatement) { + QString s = scopeStatement->fullName + "::" + command; + s.squeeze(); + return s; + } else return command; } diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 890895b9..341cc6aa 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -131,6 +131,9 @@ void CppPreprocessor::getDefineParts(const QString &input, QString &name, QStrin args = ""; } value = removeGCCAttributes(s.mid(i+1).trimmed()); + name.squeeze(); + value.squeeze(); + args.squeeze(); } void CppPreprocessor::addHardDefineByLine(const QString &line) @@ -942,9 +945,9 @@ void CppPreprocessor::parseArgs(PDefine define) if(args=="") return ; - define->argList = args.split(','); - for (int i=0;iargList.size();i++) { - define->argList[i]=define->argList[i].trimmed(); + QStringList argList = args.split(','); + for (int i=0;iargUsed.append(false); } QList tokens = tokenizeValue(define->value); @@ -956,10 +959,10 @@ void CppPreprocessor::parseArgs(PDefine define) switch(token->type) { case DefineArgTokenType::Identifier: if (token->value == "__VA_ARGS__") { - index = define->argList.indexOf("..."); + index = argList.indexOf("..."); define->varArgIndex = index; } else { - index = define->argList.indexOf(token->value); + index = argList.indexOf(token->value); } if (index>=0) { define->argUsed[index] = true; @@ -986,6 +989,7 @@ void CppPreprocessor::parseArgs(PDefine define) lastTokenType = token->type; } define->formatValue = formatStr; + define->formatValue.squeeze(); } QList CppPreprocessor::tokenizeValue(const QString &value) @@ -1456,9 +1460,9 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args) // args = args.mid(1,args.length()-2); // } - if (define->argList.length()==0) { + if (define->argUsed.length()==0) { // do nothing - } else if (define->argList.length()==1) { + } else if (define->argUsed.length()==1) { if (define->argUsed[0]) result=result.arg(args); } else { @@ -1504,25 +1508,25 @@ QString CppPreprocessor::expandFunction(PDefine define, QString args) argValues.append(args.mid(lastSplit,i-lastSplit)); #ifdef QT_DEBUG if ( - (define->varArgIndex==-1 && argValues.length() != define->argList.length()) - || (define->varArgIndex!=-1 && argValues.length() < define->argList.length()-1) + (define->varArgIndex==-1 && argValues.length() != define->argUsed.length()) + || (define->varArgIndex!=-1 && argValues.length() < define->argUsed.length()-1) ) { qDebug()<<"*** Expand Macro error ***"; qDebug()<mFileName<<":"<mIndex; - qDebug()<<"Macro: "<name<argList; + qDebug()<<"Macro: "<name<args; qDebug()<<"Actual param: "<= define->argList.length() + if (argValues.length() >= define->argUsed.length() && argValues.length()>0) { QStringList varArgs; for (int i=0;ivarArgIndex != -1 && i >= define->varArgIndex ) { varArgs.append(argValues[i].trimmed()); - } else if (iargList.length() + } else if (iargUsed.length() && define->argUsed[i]) { QString argValue = argValues[i]; result=result.arg(argValue.trimmed()); diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index 6e8aae8c..8aaac9fc 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -50,7 +50,6 @@ struct Define { QString value; QString filename; bool hardCoded;// if true, don't free memory (points to hard defines) - QStringList argList; // args list to format values QList argUsed; int varArgIndex; QString formatValue; // format template to format values @@ -145,8 +144,8 @@ enum class EvalStatementKind { }; struct StatementMatchPosition{ - int start; - int end; + uint16_t start; + uint16_t end; }; enum StatementProperty { @@ -201,10 +200,10 @@ struct Statement { // fields for code completion int usageCount; //Usage Count - int matchPosTotal; // total of matched positions - int matchPosSpan; // distance between the first match pos and the last match pos; - int firstMatchLength; // length of first match; - int caseMatched; // if match with case + uint16_t matchPosTotal; // total of matched positions + uint16_t matchPosSpan; // distance between the first match pos and the last match pos; + uint16_t firstMatchLength; // length of first match; + uint16_t caseMatched; // if match with case QList matchPositions; // definiton line/filename is valid