Refactorization:

- Optimized std::string usage
- Replaced list by vector
- Moved iterator into loop head
- Ran AStyle
This commit is contained in:
PKEuS 2016-12-05 17:30:06 +01:00
parent 76b31302eb
commit 6e8ac13325
6 changed files with 17 additions and 20 deletions

View File

@ -717,7 +717,7 @@ void CheckCondition::checkIncorrectLogicOperator()
const std::string cond1VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr2VerboseMsg + " " + tok->astOperand2()->str() + " " + expr3VerboseMsg;
const std::string cond2VerboseMsg = expr1VerboseMsg + " " + tok->str() + " " + expr3VerboseMsg;
// for the --verbose message, transform the actual condition and print it
// for the --verbose message, transform the actual condition and print it
const std::string msg = tok2->expressionString() + ". '" + cond1 + "' is equivalent to '" + cond2 + "'\n"
"The condition '" + cond1VerboseMsg + "' is equivalent to '" + cond2VerboseMsg + "'.";
redundantConditionError(tok, msg, false);

View File

@ -986,20 +986,20 @@ bool Library::isUseRetVal(const Token* ftok) const
_useretval.find(getFunctionName(ftok)) != _useretval.end());
}
std::string Library::returnValue(const Token *ftok) const
const std::string& Library::returnValue(const Token *ftok) const
{
if (isNotLibraryFunction(ftok))
return std::string();
return emptyString;
std::map<std::string, std::string>::const_iterator it = _returnValue.find(getFunctionName(ftok));
return it != _returnValue.end() ? it->second : std::string();
return it != _returnValue.end() ? it->second : emptyString;
}
std::string Library::returnValueType(const Token *ftok) const
const std::string& Library::returnValueType(const Token *ftok) const
{
if (isNotLibraryFunction(ftok))
return std::string();
return emptyString;
std::map<std::string, std::string>::const_iterator it = _returnValueType.find(getFunctionName(ftok));
return it != _returnValueType.end() ? it->second : std::string();
return it != _returnValueType.end() ? it->second : emptyString;
}
int Library::returnValueContainer(const Token *ftok) const

View File

@ -166,8 +166,8 @@ public:
bool isUseRetVal(const Token* ftok) const;
std::string returnValue(const Token *ftok) const;
std::string returnValueType(const Token *ftok) const;
const std::string& returnValue(const Token *ftok) const;
const std::string& returnValueType(const Token *ftok) const;
int returnValueContainer(const Token *ftok) const;
bool isnoreturn(const Token *ftok) const;

View File

@ -125,13 +125,14 @@ void Preprocessor::setDirectives(const simplecpp::TokenList &tokens1)
// directive list..
directives.clear();
std::list<const simplecpp::TokenList *> list;
std::vector<const simplecpp::TokenList *> list;
list.reserve(1U + tokenlists.size());
list.push_back(&tokens1);
for (std::map<std::string, simplecpp::TokenList *>::const_iterator it = tokenlists.begin(); it != tokenlists.end(); ++it) {
list.push_back(it->second);
}
for (std::list<const simplecpp::TokenList *>::const_iterator it = list.begin(); it != list.end(); ++it) {
for (std::vector<const simplecpp::TokenList *>::const_iterator it = list.begin(); it != list.end(); ++it) {
for (const simplecpp::Token *tok = (*it)->cfront(); tok; tok = tok ? tok->next : nullptr) {
if ((tok->op != '#') || (tok->previous && tok->previous->location.line == tok->location.line))
continue;
@ -557,9 +558,7 @@ void Preprocessor::setPlatformInfo(simplecpp::TokenList *tokens) const
std::string Preprocessor::getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector<std::string> &files, const bool writeLocations)
{
const std::string filename(files[0]);
const simplecpp::DUI dui = createDUI(_settings, cfg, filename);
const simplecpp::DUI dui = createDUI(_settings, cfg, files[0]);
simplecpp::OutputList outputList;
std::list<simplecpp::MacroUsage> macroUsage;
@ -747,7 +746,7 @@ bool Preprocessor::validateCfg(const std::string &cfg, const std::list<simplecpp
{
bool ret = true;
std::list<std::string> defines;
splitcfg(cfg, defines, std::string());
splitcfg(cfg, defines, emptyString);
for (std::list<std::string>::const_iterator defineIt = defines.begin(); defineIt != defines.end(); ++defineIt) {
if (defineIt->find('=') != std::string::npos)
continue;
@ -800,11 +799,9 @@ void Preprocessor::dump(std::ostream &out) const
// Create a xml directive dump.
// The idea is not that this will be readable for humans. It's a
// data dump that 3rd party tools could load and get useful info from.
std::list<Directive>::const_iterator it;
out << " <directivelist>" << std::endl;
for (it = directives.begin(); it != directives.end(); ++it) {
for (std::list<Directive>::const_iterator it = directives.begin(); it != directives.end(); ++it) {
out << " <directive "
<< "file=\"" << it->file << "\" "
<< "linenr=\"" << it->linenr << "\" "

View File

@ -4632,7 +4632,7 @@ void SymbolDatabase::setValueTypeInTokenList(Token *tokens, bool cpp, const Sett
// library function
else if (tok->previous()) {
const std::string typestr(settings->library.returnValueType(tok->previous()));
const std::string& typestr(settings->library.returnValueType(tok->previous()));
if (typestr.empty() || typestr == "iterator")
continue;
TokenList tokenList(settings);

View File

@ -2567,7 +2567,7 @@ static void valueFlowSubFunction(TokenList *tokenlist, ErrorLogger *errorLogger,
const Function * const currentFunction = tok->function();
if (!currentFunction) {
// library function?
const std::string returnValue(settings->library.returnValue(tok));
const std::string& returnValue(settings->library.returnValue(tok));
if (!returnValue.empty())
valueFlowLibraryFunction(tok->next(), returnValue, settings);
continue;