Skip to content

Commit

Permalink
removed unnecessary usage of std::istringstream
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 23, 2024
1 parent 6754685 commit 975124f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
3 changes: 1 addition & 2 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ namespace {
// TODO: improve evaluation
const Settings s;
TokenList tokenlist(&s);
std::istringstream istr(c);
tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result
tokenlist.createTokens(c.data(), c.size(), Standards::Language::C); // TODO: check result
// TODO: put in a helper
// generate links
{
Expand Down
6 changes: 2 additions & 4 deletions test/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class SimpleTokenizer : public Tokenizer {
bool cpp = true,
const std::string &configuration = emptyString)
{
std::istringstream istr(code);
if (!list.createTokens(istr, cpp ? "test.cpp" : "test.c"))
if (!list.createTokens(code, size-1, cpp ? "test.cpp" : "test.c"))
return false;

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

return simplifyTokens1(configuration);
Expand Down
4 changes: 1 addition & 3 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <cstddef>
#include <list>
#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -8939,9 +8938,8 @@ class TestClass : public TestFixture {
std::list<Check::FileInfo*> fileInfo;
for (const std::string& c: code) {
Tokenizer tokenizer(settingsDefault, *this);
std::istringstream istr(c);
const std::string filename = std::to_string(fileInfo.size()) + ".cpp";
ASSERT(tokenizer.list.createTokens(istr, filename));
ASSERT(tokenizer.list.createTokens(c.data(), c.size(), filename));
ASSERT(tokenizer.simplifyTokens1(""));
fileInfo.push_back(check.getFileInfo(tokenizer, settingsDefault));
}
Expand Down
3 changes: 1 addition & 2 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,7 @@ class TestTokenizer : public TestFixture {
{
Tokenizer tokenizer(settings1, *this);
const char code[] = "void foo(int i) { reinterpret_cast<char>(i) };";
std::istringstream istr(code);
ASSERT(tokenizer.list.createTokens(istr, "test.h"));
ASSERT(tokenizer.list.createTokens(code, "test.h"));
ASSERT_THROW_INTERNAL(tokenizer.simplifyTokens1(""), SYNTAX);
}
}
Expand Down
5 changes: 2 additions & 3 deletions test/testtokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ class TestTokenList : public TestFixture {
}

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

TokenList tokenlist(&settings);
std::istringstream istr(s);
ASSERT(tokenlist.createTokens(istr, Standards::Language::C));
ASSERT(tokenlist.createTokens(code, Standards::Language::C));
// TODO: put this logic in TokenList
// generate links
{
Expand Down
4 changes: 1 addition & 3 deletions test/testunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "tokenlist.h"

#include <cstddef>
#include <sstream>
#include <string>

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

Tokenizer tokenizer(settings, *this);
std::istringstream istr(code);
ASSERT(tokenizer.list.createTokens(istr, fname));
ASSERT(tokenizer.list.createTokens(code, fname));
ASSERT(tokenizer.simplifyTokens1(""));

c.parseTokens(tokenizer, settings);
Expand Down

0 comments on commit 975124f

Please sign in to comment.