inline parseLine()

this should be marginally faster and it allows turning a few members
into locals.
This commit is contained in:
Oswald Buddenhagen
2009-07-16 18:11:09 +02:00
parent 67e30ed8c9
commit 81baf03476

View File

@@ -139,7 +139,6 @@ public:
ProBlock *currentBlock(); ProBlock *currentBlock();
void updateItem(); void updateItem();
void parseLine(const QString &line);
void insertVariable(const ushort **pCur, const ushort *end); void insertVariable(const ushort **pCur, const ushort *end);
void insertOperator(const char op); void insertOperator(const char op);
void insertComment(const QString &comment); void insertComment(const QString &comment);
@@ -154,9 +153,6 @@ public:
QString m_proitem; QString m_proitem;
QString m_pendingComment; QString m_pendingComment;
ushort *m_proitemPtr; ushort *m_proitemPtr;
bool m_contNextLine;
bool m_inQuote;
int m_parens;
enum StrState { NotStarted, Started, PutSpace }; enum StrState { NotStarted, Started, PutSpace };
@@ -287,117 +283,105 @@ bool ProFileEvaluator::Private::read(ProFile *pro, QTextStream *ts)
// Parser state // Parser state
m_block = 0; m_block = 0;
m_commentItem = 0; m_commentItem = 0;
m_inQuote = false;
m_parens = 0;
m_contNextLine = false;
m_lineNo = 1; m_lineNo = 1;
m_blockstack.clear(); m_blockstack.clear();
m_blockstack.push(pro); m_blockstack.push(pro);
int parens = 0;
bool inQuote = false;
bool escaped = false;
while (!ts->atEnd()) { while (!ts->atEnd()) {
QString line = ts->readLine(); QString line = ts->readLine();
parseLine(line); const ushort *cur = (const ushort *)line.unicode(),
++m_lineNo; *end = cur + line.length();
} m_proitem.reserve(line.length());
return true; m_proitemPtr = (ushort *)m_proitem.unicode();
} nextItem:
ushort *ptr = m_proitemPtr;
void ProFileEvaluator::Private::parseLine(const QString &line) StrState sts = NotStarted;
{ while (cur < end) {
const ushort *cur = (const ushort *)line.unicode(), ushort c = *cur++;
*end = cur + line.length(); if (c == '#') { // Yep - no escaping possible
int parens = m_parens; m_proitemPtr = ptr;
bool inQuote = m_inQuote; insertComment(line.right(end - cur).simplified());
bool escaped = false; goto done;
m_proitem.reserve(line.length());
m_proitemPtr = (ushort *)m_proitem.unicode();
nextItem:
ushort *ptr = m_proitemPtr;
StrState sts = NotStarted;
while (cur < end) {
ushort c = *cur++;
if (c == '#') { // Yep - no escaping possible
m_proitemPtr = ptr;
insertComment(line.right(end - cur).simplified());
goto done;
}
if (!escaped) {
if (c == '\\') {
escaped = true;
goto putch;
} else if (c == '"') {
inQuote = !inQuote;
goto putch;
} }
} else { if (!escaped) {
escaped = false; if (c == '\\') {
} escaped = true;
if (!inQuote) { goto putch;
if (c == '(') { } else if (c == '"') {
++parens; inQuote = !inQuote;
} else if (c == ')') { goto putch;
--parens; }
} else if (!parens) { } else {
if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) { escaped = false;
if (c == ' ' || c == '\t') { }
m_proitemPtr = ptr; if (!inQuote) {
updateItem(); if (c == '(') {
goto nextItem; ++parens;
} } else if (c == ')') {
} else { --parens;
if (c == ':') { } else if (!parens) {
m_proitemPtr = ptr; if (m_block && (m_block->blockKind() & ProBlock::VariableKind)) {
enterScope(false); if (c == ' ' || c == '\t') {
goto nextItem; m_proitemPtr = ptr;
} updateItem();
if (c == '{') { goto nextItem;
m_proitemPtr = ptr; }
enterScope(true); } else {
goto nextItem; if (c == ':') {
} m_proitemPtr = ptr;
if (c == '}') { enterScope(false);
m_proitemPtr = ptr; goto nextItem;
leaveScope(); }
goto nextItem; if (c == '{') {
} m_proitemPtr = ptr;
if (c == '=') { enterScope(true);
m_proitemPtr = ptr; goto nextItem;
insertVariable(&cur, end); }
goto nextItem; if (c == '}') {
} m_proitemPtr = ptr;
if (c == '|' || c == '!') { leaveScope();
m_proitemPtr = ptr; goto nextItem;
insertOperator(c); }
goto nextItem; if (c == '=') {
m_proitemPtr = ptr;
insertVariable(&cur, end);
goto nextItem;
}
if (c == '|' || c == '!') {
m_proitemPtr = ptr;
insertOperator(c);
goto nextItem;
}
} }
} }
} }
}
if (c == ' ' || c == '\t') { if (c == ' ' || c == '\t') {
if (sts == Started) if (sts == Started)
sts = PutSpace; sts = PutSpace;
} else { } else {
putch: putch:
if (sts == PutSpace) if (sts == PutSpace)
*ptr++ = ' '; *ptr++ = ' ';
*ptr++ = c; *ptr++ = c;
sts = Started; sts = Started;
}
} }
m_proitemPtr = ptr;
done:
if (escaped) {
--m_proitemPtr;
updateItem();
} else {
updateItem();
finalizeBlock();
}
++m_lineNo;
} }
m_proitemPtr = ptr; return true;
m_contNextLine = escaped;
done:
m_inQuote = inQuote;
m_parens = parens;
if (m_contNextLine) {
--m_proitemPtr;
updateItem();
} else {
updateItem();
finalizeBlock();
}
} }
void ProFileEvaluator::Private::finalizeBlock() void ProFileEvaluator::Private::finalizeBlock()