diff options
Diffstat (limited to 'Source/WebCore/html/parser/HTMLParserScheduler.h')
-rw-r--r-- | Source/WebCore/html/parser/HTMLParserScheduler.h | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/Source/WebCore/html/parser/HTMLParserScheduler.h b/Source/WebCore/html/parser/HTMLParserScheduler.h index 862bb62a4..a79e06450 100644 --- a/Source/WebCore/html/parser/HTMLParserScheduler.h +++ b/Source/WebCore/html/parser/HTMLParserScheduler.h @@ -23,13 +23,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HTMLParserScheduler_h -#define HTMLParserScheduler_h +#pragma once #include "NestingLevelIncrementer.h" #include "Timer.h" #include <wtf/CurrentTime.h> -#include <wtf/PassOwnPtr.h> #include <wtf/RefPtr.h> #if PLATFORM(IOS) @@ -55,9 +53,8 @@ public: PumpSession(unsigned& nestingLevel, Document*); ~PumpSession(); - int processedTokens; + unsigned processedTokens; double startTime; - bool needsYield; bool didSeeScript; }; @@ -67,29 +64,19 @@ public: explicit HTMLParserScheduler(HTMLDocumentParser&); ~HTMLParserScheduler(); - // Inline as this is called after every token in the parser. - void checkForYieldBeforeToken(PumpSession& session) + bool shouldYieldBeforeToken(PumpSession& session) { #if PLATFORM(IOS) if (WebThreadShouldYield()) - session.needsYield = true; + return true; #endif - if (session.processedTokens > m_parserChunkSize || session.didSeeScript) { - // monotonicallyIncreasingTime() can be expensive. By delaying, we avoided calling - // monotonicallyIncreasingTime() when constructing non-yielding PumpSessions. - if (!session.startTime) - session.startTime = monotonicallyIncreasingTime(); - - session.processedTokens = 0; - session.didSeeScript = false; - - double elapsedTime = monotonicallyIncreasingTime() - session.startTime; - if (elapsedTime > m_parserTimeLimit) - session.needsYield = true; - } + if (UNLIKELY(session.processedTokens > numberOfTokensBeforeCheckingForYield || session.didSeeScript)) + return checkForYield(session); + ++session.processedTokens; + return false; } - void checkForYieldBeforeScript(PumpSession&); + bool shouldYieldBeforeExecutingScript(PumpSession&); void scheduleForResume(); bool isScheduledForResume() const { return m_isSuspendedWithActiveTimer || m_continueNextChunkTimer.isActive(); } @@ -98,19 +85,34 @@ public: void resume(); private: - void continueNextChunkTimerFired(Timer<HTMLParserScheduler>&); + static const unsigned numberOfTokensBeforeCheckingForYield = 4096; // Performance optimization + + void continueNextChunkTimerFired(); + + bool checkForYield(PumpSession& session) + { + session.processedTokens = 1; + session.didSeeScript = false; + + // monotonicallyIncreasingTime() can be expensive. By delaying, we avoided calling + // monotonicallyIncreasingTime() when constructing non-yielding PumpSessions. + if (!session.startTime) { + session.startTime = monotonicallyIncreasingTime(); + return false; + } + + double elapsedTime = monotonicallyIncreasingTime() - session.startTime; + return elapsedTime > m_parserTimeLimit; + } HTMLDocumentParser& m_parser; double m_parserTimeLimit; - int m_parserChunkSize; - Timer<HTMLParserScheduler> m_continueNextChunkTimer; + Timer m_continueNextChunkTimer; bool m_isSuspendedWithActiveTimer; #if !ASSERT_DISABLED bool m_suspended; #endif }; -} - -#endif +} // namespace WebCore |