From 9fe8ae452aa039bf5443770a2f936b4faa94b3bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 17 Mar 2009 18:55:28 +0100 Subject: [PATCH] Refactoring the code for the templates handling --- src/tokenize.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index bcd3194c3..32bbeae99 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -535,20 +535,23 @@ void Tokenizer::tokenize(std::istream &code, const char FileName[]) int indentlevel = 0; for (; tok3; tok3 = tok3->next()) { - for (unsigned int i = 0; i <= type.size(); ++i) { - if (i == type.size()) - { - if (tok3->str() == name) - addtoken(name2.c_str(), tok3->linenr(), tok3->fileIndex()); - else - addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex()); - } - else if (tok3->str() == type[i]) - { - addtoken(types2[i].c_str(), tok3->linenr(), tok3->fileIndex()); - break; - } + // search for this token in the type vector + unsigned int itype = 0; + while (itype < type.size() && type[itype] != tok3->str()) + ++itype; + + // replace type with given type.. + if (itype < type.size()) + addtoken(types2[itype].c_str(), tok3->linenr(), tok3->fileIndex()); + + // replace name.. + else if (tok3->str() == name) + addtoken(name2.c_str(), tok3->linenr(), tok3->fileIndex()); + + // copy + else + addtoken(tok3->str().c_str(), tok3->linenr(), tok3->fileIndex()); } if (tok3->str() == "{")