summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/parser/HTMLParserScheduler.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/parser/HTMLParserScheduler.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/html/parser/HTMLParserScheduler.h')
-rw-r--r--Source/WebCore/html/parser/HTMLParserScheduler.h58
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