CheckAutoVariables: change type of vda_list member to std::set.

Change type of vda_list from std::list to std::set. It allows to us
use find() method instead of self-written loop which may be slow.

No functional change.
This commit is contained in:
Slava Semushin 2009-08-16 15:59:47 +07:00
parent 475ef4213b
commit ec81080d0b
2 changed files with 7 additions and 12 deletions

View File

@ -90,13 +90,7 @@ bool CheckAutoVariables::isAutoVar(unsigned int varId)
bool CheckAutoVariables::isAutoVarArray(unsigned int varId)
{
std::list<unsigned int>::iterator id_vd;
for (id_vd = vda_list.begin(); id_vd != vda_list.end(); ++id_vd)
{
if (*id_vd == varId)
return true;
}
return false;
return (vda_list.find(varId) != vda_list.end());
}
void print(const Token *tok, int num)
@ -143,9 +137,9 @@ void CheckAutoVariables::addVD(const Token* tok)
vd_list.push_back(tok->varId());
}
void CheckAutoVariables::addVDA(const Token* tok)
void CheckAutoVariables::addVDA(unsigned int varId)
{
vda_list.push_back(tok->varId());
vda_list.insert(varId);
}
void CheckAutoVariables::autoVariables()
@ -193,7 +187,7 @@ void CheckAutoVariables::autoVariables()
// Inside a function body
else if (bindent > 0 && Token::Match(tok, "%type% %var% ["))
{
addVDA(tok->tokAt(1));
addVDA(tok->next()->varId());
}
else if (bindent > 0 && Token::Match(tok, "%var% %var% ;") && !isExternOrStatic(tok)) //Inside a function
{

View File

@ -25,6 +25,7 @@
#include "check.h"
#include "token.h"
#include <list>
#include <set>
/// @addtogroup Checks
/// @{
@ -58,12 +59,12 @@ public:
private:
std::list<std::string> fp_list;
std::list<unsigned int> vd_list;
std::list<unsigned int> vda_list;
std::set<unsigned int> vda_list;
bool errorAv(const Token* left, const Token* right);
bool isAutoVar(unsigned int varId);
bool isAutoVarArray(unsigned int varId);
void addVD(const Token* t);
void addVDA(const Token* t);
void addVDA(unsigned int varId);