Bug 458440 - Don't create a speculative parser for an empty string. Also, avoid doing work that the scanner will happily do for us. r+sr=jst

This commit is contained in:
Blake Kaplan 2008-10-03 14:11:12 -07:00
Родитель 2d6287451f
Коммит c2c3c2f8eb
1 изменённых файлов: 10 добавлений и 7 удалений

Просмотреть файл

@ -206,6 +206,7 @@ public:
mCurrentlyParsing(0),
mNumURIs(0),
mNumConsumed(0),
mContext(nsnull),
mTerminated(PR_FALSE) {
}
@ -372,8 +373,10 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsSpeculativeScriptThread, nsIRunnable)
NS_IMETHODIMP
nsSpeculativeScriptThread::Run()
{
nsScannerIterator start;
mScanner->CurrentPosition(start);
NS_ASSERTION(!NS_IsMainThread(), "Speculative parsing on the main thread?");
mNumConsumed = 0;
mTokenizer->WillTokenize(PR_FALSE, &mTokenAllocator);
while (mKeepParsing) {
PRBool flushTokens = PR_FALSE;
@ -382,6 +385,8 @@ nsSpeculativeScriptThread::Run()
break;
}
mNumConsumed += mScanner->Mark();
// TODO Don't pop the tokens.
CToken *token;
while (mKeepParsing && NS_SUCCEEDED(rv) && (token = mTokenizer->PopToken())) {
@ -392,11 +397,6 @@ nsSpeculativeScriptThread::Run()
nsAutoLock al(mLock.get());
nsScannerIterator end;
mScanner->CurrentPosition(end);
mNumConsumed = Distance(start, end);
mCurrentlyParsing = 0;
PR_NotifyCondVar(mCVar.get());
return NS_OK;
@ -446,6 +446,9 @@ nsSpeculativeScriptThread::StartParsing(nsParser *aParser)
}
mTokenizer->CopyState(context->mTokenizer);
context->mScanner->CopyUnusedData(toScan);
if (toScan.IsEmpty()) {
return NS_OK;
}
} else if (context == mContext) {
// Don't parse the same part of the document twice.
nsScannerIterator end;