ISstream micro-optimizations

This commit is contained in:
Mark Olesen
2009-08-12 16:49:34 +02:00
parent 920fa49e7e
commit dd5021470e

View File

@ -45,40 +45,46 @@ char Foam::ISstream::nextValid()
// Return if stream is bad - ie, previous get() failed // Return if stream is bad - ie, previous get() failed
if (bad() || isspace(c)) if (bad() || isspace(c))
{ {
return 0; break;
} }
// Is this the start of a C/C++ comment? // Is this the start of a C/C++ comment?
if (c == '/') if (c == '/')
{ {
// If cannot get another character, return this one
if (!get(c)) if (!get(c))
{ {
// cannot get another character - return this one
return '/'; return '/';
} }
if (c == '/') if (c == '/')
{ {
// This is the start of a C++ style one-line comment // C++ style single-line comment - skip through past end-of-line
while (get(c) && c != '\n') while (get(c) && c != '\n')
{} {}
} }
else if (c == '*') else if (c == '*')
{ {
// This is the start of a C style comment // within a C-style comment
while (true) while (true)
{ {
// search for end of C-style comment - '*/'
if (get(c) && c == '*') if (get(c) && c == '*')
{ {
if (get(c) && c == '/') if (get(c))
{ {
if (c == '/')
{
// matched '*/'
break; break;
} }
else else if (c == '*')
{ {
// check again
putback(c); putback(c);
} }
} }
}
if (!good()) if (!good())
{ {
@ -86,17 +92,21 @@ char Foam::ISstream::nextValid()
} }
} }
} }
else // A lone '/' so return it. else
{ {
// The '/' did not start a C/C++ comment - return it
putback(c); putback(c);
return '/'; return '/';
} }
} }
else // c is a valid character so return it else
{ {
// a valid character - return it
return c; return c;
} }
} }
return 0;
} }
@ -277,8 +287,8 @@ Foam::Istream& Foam::ISstream::read(token& t)
// } // }
} }
// nothing converted (bad format), or trailing junk // not everything converted: bad format or trailing junk
if (endptr == buf || *endptr != '\0') if (*endptr)
{ {
t.setBad(); t.setBad();
} }
@ -289,7 +299,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
} }
// Should be a word (which can be a single character) // Should be a word (which can also be a single character)
default: default:
{ {
putback(c); putback(c);