Refactorization: Store minsizes in vector instead of list which has less overhead

This commit is contained in:
PKEuS 2017-03-27 17:33:26 +02:00
parent 63d39390b4
commit 2938278f00
4 changed files with 9 additions and 9 deletions

View File

@ -313,7 +313,7 @@ static bool bailoutIfSwitch(const Token *tok, const unsigned int varid)
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &minsizes, const Token * const ftok, const MathLib::bigint arraySize, const Token **charSizeToken, const Settings * const settings) static bool checkMinSizes(const std::vector<Library::ArgumentChecks::MinSize> &minsizes, const Token * const ftok, const MathLib::bigint arraySize, const Token **charSizeToken, const Settings * const settings)
{ {
if (charSizeToken) if (charSizeToken)
*charSizeToken = nullptr; *charSizeToken = nullptr;
@ -323,7 +323,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
// All conditions must be true // All conditions must be true
bool error = true; bool error = true;
for (std::list<Library::ArgumentChecks::MinSize>::const_iterator minsize = minsizes.begin(); minsize != minsizes.end(); ++minsize) { for (std::vector<Library::ArgumentChecks::MinSize>::const_iterator minsize = minsizes.begin(); minsize != minsizes.end(); ++minsize) {
if (!error) if (!error)
return false; return false;
error = false; error = false;
@ -383,7 +383,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack) void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack)
{ {
const std::list<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex); const std::vector<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex);
if (minsizes) { if (minsizes) {
MathLib::bigint arraySize = arrayInfo.element_size(); MathLib::bigint arraySize = arrayInfo.element_size();
@ -1704,7 +1704,7 @@ void CheckBufferOverrun::checkStringArgument()
const Token *strtoken = argtok->getValueTokenMinStrSize(); const Token *strtoken = argtok->getValueTokenMinStrSize();
if (!strtoken) if (!strtoken)
continue; continue;
const std::list<Library::ArgumentChecks::MinSize> *minsizes = _settings->library.argminsizes(tok, argnr); const std::vector<Library::ArgumentChecks::MinSize> *minsizes = _settings->library.argminsizes(tok, argnr);
if (!minsizes) if (!minsizes)
continue; continue;
if (checkMinSizes(*minsizes, tok, Token::getStrSize(strtoken), nullptr, _settings)) if (checkMinSizes(*minsizes, tok, Token::getStrSize(strtoken), nullptr, _settings))

View File

@ -623,9 +623,10 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9') if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
return Error(BAD_ATTRIBUTE_VALUE, argattr); return Error(BAD_ATTRIBUTE_VALUE, argattr);
ac.minsizes.reserve(type == ArgumentChecks::MinSize::MUL ? 2 : 1);
ac.minsizes.push_back(ArgumentChecks::MinSize(type,argattr[0]-'0')); ac.minsizes.push_back(ArgumentChecks::MinSize(type,argattr[0]-'0'));
if (type == ArgumentChecks::MinSize::MUL) { if (type == ArgumentChecks::MinSize::MUL) {
const char *arg2attr = argnode->Attribute("arg2"); const char *arg2attr = argnode->Attribute("arg2");
if (!arg2attr) if (!arg2attr)
return Error(MISSING_ATTRIBUTE, "arg2"); return Error(MISSING_ATTRIBUTE, "arg2");
if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9') if (strlen(arg2attr) != 1 || arg2attr[0]<'0' || arg2attr[0]>'9')

View File

@ -29,7 +29,6 @@
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
#include <list>
#include <vector> #include <vector>
namespace tinyxml2 { namespace tinyxml2 {
@ -255,7 +254,7 @@ public:
int arg; int arg;
int arg2; int arg2;
}; };
std::list<MinSize> minsizes; std::vector<MinSize> minsizes;
}; };
@ -310,7 +309,7 @@ public:
bool hasminsize(const std::string &functionName) const; bool hasminsize(const std::string &functionName) const;
const std::list<ArgumentChecks::MinSize> *argminsizes(const Token *ftok, int argnr) const { const std::vector<ArgumentChecks::MinSize> *argminsizes(const Token *ftok, int argnr) const {
const ArgumentChecks *arg = getarg(ftok, argnr); const ArgumentChecks *arg = getarg(ftok, argnr);
return arg ? &arg->minsizes : nullptr; return arg ? &arg->minsizes : nullptr;
} }

View File

@ -339,7 +339,7 @@ private:
tokenList.front()->next()->astOperand1(tokenList.front()); tokenList.front()->next()->astOperand1(tokenList.front());
// arg1: type=strlen arg2 // arg1: type=strlen arg2
const std::list<Library::ArgumentChecks::MinSize> *minsizes = library.argminsizes(tokenList.front(),1); const std::vector<Library::ArgumentChecks::MinSize> *minsizes = library.argminsizes(tokenList.front(),1);
ASSERT_EQUALS(true, minsizes != nullptr); ASSERT_EQUALS(true, minsizes != nullptr);
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U); ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
if (minsizes && minsizes->size() == 1U) { if (minsizes && minsizes->size() == 1U) {