diff --git a/lib/token.cpp b/lib/token.cpp index d3210bd8c..7d2c8a8c8 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -191,43 +191,17 @@ void Token::deleteNext(unsigned long index) void Token::swapWithNext() { if (_next) { - Token temp(0); - - temp._str = _next->_str; - temp._tokType = _next->_tokType; - temp._flags = _next->_flags; - temp._varId = _next->_varId; - temp._fileIndex = _next->_fileIndex; - temp._link = _next->_link; - temp._scope = _next->_scope; - temp._function = _next->_function; - temp._originalName = _next->_originalName; - temp.values = _next->values; - temp._progressValue = _next->_progressValue; - - _next->_str = _str; - _next->_tokType = _tokType; - _next->_flags = _flags; - _next->_varId = _varId; - _next->_fileIndex = _fileIndex; - _next->_link = _link; - _next->_scope = _scope; - _next->_function = _function; - _next->_originalName = _originalName; - _next->values = values; - _next->_progressValue = _progressValue; - - _str = temp._str; - _tokType = temp._tokType; - _flags = temp._flags; - _varId = temp._varId; - _fileIndex = temp._fileIndex; - _link = temp._link; - _scope = temp._scope; - _function = temp._function; - _originalName = temp._originalName; - values = temp.values; - _progressValue = temp._progressValue; + std::swap(_str, _next->_str); + std::swap(_tokType, _next->_tokType); + std::swap(_flags, _next->_flags); + std::swap(_varId, _next->_varId); + std::swap(_fileIndex, _next->_fileIndex); + std::swap(_link, _next->_link); + std::swap(_scope, _next->_scope); + std::swap(_function, _next->_function); + std::swap(_originalName, _next->_originalName); + std::swap(values, _next->values); + std::swap(_progressValue, _next->_progressValue); } } diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 6957eea64..e16272168 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -108,7 +108,7 @@ void TokenList::deleteTokens(Token *tok) // add a token. //--------------------------------------------------------------------------- -void TokenList::addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split) +void TokenList::addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split) { if (str.empty()) return; @@ -129,23 +129,20 @@ void TokenList::addtoken(const std::string & str, const unsigned int lineno, con } // Replace hexadecimal value with decimal - std::string str2; if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) { std::ostringstream str2stream; str2stream << MathLib::toULongNumber(str); - str2 = str2stream.str(); + str = str2stream.str(); } else if (str.compare(0, 5, "_Bool") == 0) { - str2 = "bool"; - } else { - str2 = str; + str = "bool"; } if (_back) { - _back->insertToken(str2); + _back->insertToken(str); } else { _front = new Token(&_back); _back = _front; - _back->str(str2); + _back->str(str); } if (isCPP() && str == "delete") diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 80b07ea8f..3ea796d81 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -59,7 +59,7 @@ public: */ static void deleteTokens(Token *tok); - void addtoken(const std::string & str, const unsigned int lineno, const unsigned int fileno, bool split = false); + void addtoken(std::string str, const unsigned int lineno, const unsigned int fileno, bool split = false); void addtoken(const Token *tok, const unsigned int lineno, const unsigned int fileno); static void insertTokens(Token *dest, const Token *src, unsigned int n); diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index ef089a144..35fa966a9 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -84,60 +84,54 @@ private: } void many_threads() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n"; - oss << " char *a = malloc(10);\n"; - oss << " return 0;\n" - << "}"; - check(20, 100, 100, oss.str()); + check(20, 100, 100, + "int main()\n" + "{\n" + " char *a = malloc(10);\n" + " return 0;\n" + "}"); } void no_errors_more_files() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n" - << " return 0;\n" - << "}\n"; - check(2, 3, 0, oss.str()); + check(2, 3, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); } void no_errors_less_files() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n" - << " return 0;\n" - << "}\n"; - check(2, 1, 0, oss.str()); + check(2, 1, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); } void no_errors_equal_amount_files() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n" - << " return 0;\n" - << "}\n"; - check(2, 2, 0, oss.str()); + check(2, 2, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}"); } void one_error_less_files() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n" - << " {char *a = malloc(10);}\n" - << " return 0;\n" - << "}\n"; - check(2, 1, 1, oss.str()); + check(2, 1, 1, + "int main()\n" + "{\n" + " {char *a = malloc(10);}\n" + " return 0;\n" + "}"); } void one_error_several_files() { - std::ostringstream oss; - oss << "int main()\n" - << "{\n" - << " {char *a = malloc(10);}\n" - << " return 0;\n" - << "}\n"; - check(2, 20, 20, oss.str()); + check(2, 20, 20, + "int main()\n" + "{\n" + " {char *a = malloc(10);}\n" + " return 0;\n" + "}"); } };