From d4765bccc3000312fba7f2dd12cce29d9fd972dc Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 2 Apr 2014 17:33:04 +0200 Subject: [PATCH] Refactorized inefficient usage of std::string and const char[] (part 2). --- test/testmemleak.cpp | 18 +++++++++--------- test/testsimplifytokens.cpp | 3 +-- test/testtokenize.cpp | 3 +-- test/testvalueflow.cpp | 6 +++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 384dc8370..94d715fd2 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2476,7 +2476,7 @@ private: " char *p = a(len);\n" " delete [] p;\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); check("char *a(char *a)\n" "{\n" @@ -2491,7 +2491,7 @@ private: " else\n" " free(p);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); check("char *a()\n" "{\n" @@ -2502,7 +2502,7 @@ private: " char *p = a();\n" " free(p);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); check("gchar *a()\n" "{\n" " return g_malloc(10);\n" @@ -2512,7 +2512,7 @@ private: " gchar *p = a();\n" " g_free(p);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); } void allocfunc3() { @@ -2623,7 +2623,7 @@ private: " foo(&tmp);\n" " free(tmp);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); check("void foo(gchar **str)\n" "{\n" " g_free(*str);\n" @@ -2637,7 +2637,7 @@ private: " foo(&tmp);\n" " g_free(tmp);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); //#ticket 1789: getcode other function: check("void foo(char **str)\n" @@ -2655,7 +2655,7 @@ private: " foo(&tmp);\n" " free(tmp);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); } @@ -2675,7 +2675,7 @@ private: "\n" " free(expr);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); check("static FILE* data()\n" "{\n" " return fopen(\"data.txt\",\"rt\");\n" @@ -2691,7 +2691,7 @@ private: "\n" " g_free(expr);\n" "}"); - ASSERT_EQUALS(std::string(""), errout.str()); + ASSERT_EQUALS("", errout.str()); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 9ab558959..161097432 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -5241,8 +5241,7 @@ private: void simplifyTypedef75() { // ticket #2426 const char code[] = "typedef _Packed struct S { long l; };\n"; - const std::string expected = ""; - ASSERT_EQUALS(expected, tok(code)); + ASSERT_EQUALS("", tok(code)); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index cdb43f0c6..e968df666 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7103,8 +7103,7 @@ private: } void functionpointer4() { - const char code[] = "" - "struct S\n" + const char code[] = "struct S\n" "{\n" " typedef void (*FP)();\n" " virtual FP getFP();\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 3c05389e0..501b1da75 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -57,7 +57,7 @@ private: TEST_CASE(valueFlowSubFunction); } - bool testValueOfX(const std::string &code, unsigned int linenr, int value) { + bool testValueOfX(const char code[], unsigned int linenr, int value) { Settings settings; // strcpy cfg @@ -269,8 +269,8 @@ private: " setx(x);\n" " if (x == 1) {}\n" "}"; - ASSERT_EQUALS(true, testValueOfX(std::string("void setx(int x);")+code, 2U, 1)); - ASSERT_EQUALS(false, testValueOfX(std::string("void setx(int &x);")+code, 2U, 1)); + ASSERT_EQUALS(true, testValueOfX((std::string("void setx(int x);")+code).c_str(), 2U, 1)); + ASSERT_EQUALS(false, testValueOfX((std::string("void setx(int &x);")+code).c_str(), 2U, 1)); ASSERT_EQUALS(true, testValueOfX(code, 2U, 1)); code = "void f(char* x) {\n"