Skip to content

Commit 975124f

Browse files
committed
removed unnecessary usage of std::istringstream
1 parent 6754685 commit 975124f

6 files changed

Lines changed: 8 additions & 17 deletions

File tree

lib/importproject.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ namespace {
574574
// TODO: improve evaluation
575575
const Settings s;
576576
TokenList tokenlist(&s);
577-
std::istringstream istr(c);
578-
tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result
577+
tokenlist.createTokens(c.data(), c.size(), Standards::Language::C); // TODO: check result
579578
// TODO: put in a helper
580579
// generate links
581580
{

test/helpers.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ class SimpleTokenizer : public Tokenizer {
8282
bool cpp = true,
8383
const std::string &configuration = emptyString)
8484
{
85-
std::istringstream istr(code);
86-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
85+
if (!list.createTokens(code, size-1, cpp ? "test.cpp" : "test.c"))
8786
return false;
8887

8988
return simplifyTokens1(configuration);
@@ -94,8 +93,7 @@ class SimpleTokenizer : public Tokenizer {
9493
bool cpp = true,
9594
const std::string &configuration = emptyString)
9695
{
97-
std::istringstream istr(code);
98-
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
96+
if (!list.createTokens(code.c_str(), code.size(), cpp ? "test.cpp" : "test.c"))
9997
return false;
10098

10199
return simplifyTokens1(configuration);

test/testclass.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include <cstddef>
2929
#include <list>
30-
#include <sstream>
3130
#include <string>
3231
#include <vector>
3332

@@ -8939,9 +8938,8 @@ class TestClass : public TestFixture {
89398938
std::list<Check::FileInfo*> fileInfo;
89408939
for (const std::string& c: code) {
89418940
Tokenizer tokenizer(settingsDefault, *this);
8942-
std::istringstream istr(c);
89438941
const std::string filename = std::to_string(fileInfo.size()) + ".cpp";
8944-
ASSERT(tokenizer.list.createTokens(istr, filename));
8942+
ASSERT(tokenizer.list.createTokens(c.data(), c.size(), filename));
89458943
ASSERT(tokenizer.simplifyTokens1(""));
89468944
fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault));
89478945
}

test/testtokenize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,7 @@ class TestTokenizer : public TestFixture {
833833
{
834834
Tokenizer tokenizer(settings1, *this);
835835
const char code[] = "void foo(int i) { reinterpret_cast<char>(i) };";
836-
std::istringstream istr(code);
837-
ASSERT(tokenizer.list.createTokens(istr, "test.h"));
836+
ASSERT(tokenizer.list.createTokens(code, "test.h"));
838837
ASSERT_THROW_INTERNAL(tokenizer.simplifyTokens1(""), SYNTAX);
839838
}
840839
}

test/testtokenlist.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ class TestTokenList : public TestFixture {
164164
}
165165

166166
void ast1() const {
167-
const std::string s = "('Release|x64' == 'Release|x64');";
167+
const char code[] = "('Release|x64' == 'Release|x64');";
168168

169169
TokenList tokenlist(&settings);
170-
std::istringstream istr(s);
171-
ASSERT(tokenlist.createTokens(istr, Standards::Language::C));
170+
ASSERT(tokenlist.createTokens(code, Standards::Language::C));
172171
// TODO: put this logic in TokenList
173172
// generate links
174173
{

test/testunusedfunctions.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "tokenlist.h"
2727

2828
#include <cstddef>
29-
#include <sstream>
3029
#include <string>
3130

3231
class TestUnusedFunctions : public TestFixture {
@@ -573,8 +572,7 @@ class TestUnusedFunctions : public TestFixture {
573572
const std::string fname = "test" + std::to_string(i) + ".cpp";
574573

575574
Tokenizer tokenizer(settings, *this);
576-
std::istringstream istr(code);
577-
ASSERT(tokenizer.list.createTokens(istr, fname));
575+
ASSERT(tokenizer.list.createTokens(code, fname));
578576
ASSERT(tokenizer.simplifyTokens1(""));
579577

580578
c.parseTokens(tokenizer, settings);

0 commit comments

Comments
 (0)