Skip to content

Commit dec5f95

Browse files
committed
removed unnecessary usage of std::istringstream
1 parent 9cf7b7c commit dec5f95

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/importproject.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ namespace {
533533
// TODO: improve evaluation
534534
const Settings s;
535535
TokenList tokenlist(s, Standards::Language::C);
536-
std::istringstream istr(c);
537-
tokenlist.createTokens(istr); // TODO: check result
536+
tokenlist.createTokens(c.data(), c.size()); // TODO: check result
538537
// TODO: put in a helper
539538
// generate links
540539
{

test/helpers.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,36 @@ class SimpleTokenizer : public Tokenizer {
6161
template<size_t size>
6262
bool tokenize(const char (&code)[size])
6363
{
64-
std::istringstream istr(code);
65-
return tokenize(istr, std::string(list.isCPP() ? "test.cpp" : "test.c"));
64+
return tokenize(code, size-1, std::string(list.isCPP() ? "test.cpp" : "test.c"));
6665
}
6766

6867
bool tokenize(const std::string& code)
6968
{
70-
std::istringstream istr(code);
71-
return tokenize(istr, std::string(list.isCPP() ? "test.cpp" : "test.c"));
69+
return tokenize(code.data(), code.size(), std::string(list.isCPP() ? "test.cpp" : "test.c"));
7270
}
7371

7472
private:
7573
/**
7674
* Tokenize code
77-
* @param istr The code as stream
75+
* @param code The code
7876
* @param filename Indicates if the code is C++
7977
* @return false if source code contains syntax errors
8078
*/
81-
bool tokenize(std::istream& istr,
79+
template<size_t size>
80+
bool tokenize(const char (&code)[size],
81+
const std::string& filename)
82+
{
83+
return tokenize(code, size-1, filename);
84+
}
85+
86+
bool tokenize(const char* code,
87+
std::size_t size,
8288
const std::string& filename)
8389
{
8490
if (list.front())
8591
throw std::runtime_error("token list is not empty");
8692
list.appendFileIfNew(filename);
87-
if (!list.createTokens(istr))
93+
if (!list.createTokens(code, size))
8894
return false;
8995

9096
return simplifyTokens1("");

test/testtokenize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,8 @@ class TestTokenizer : public TestFixture {
910910
{
911911
TokenList tokenlist{settings1, Standards::Language::C}; // headers are treated as C files
912912
const char code[] = "void foo(int i) { reinterpret_cast<char>(i) };";
913-
std::istringstream istr(code);
914913
tokenlist.appendFileIfNew("test.h");
915-
ASSERT(tokenlist.createTokens(istr));
914+
ASSERT(tokenlist.createTokens(code));
916915
Tokenizer tokenizer(std::move(tokenlist), *this);
917916
ASSERT_THROW_INTERNAL(tokenizer.simplifyTokens1(""), SYNTAX);
918917
}

test/testtokenlist.cpp

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

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

170170
TokenList tokenlist(settingsDefault, Standards::Language::C);
171-
std::istringstream istr(s);
172-
ASSERT(tokenlist.createTokens(istr));
171+
ASSERT(tokenlist.createTokens(code));
173172
// TODO: put this logic in TokenList
174173
// generate links
175174
{

0 commit comments

Comments
 (0)