| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // These numbers have not been tuned. | 47 // These numbers have not been tuned. |
| 48 static const size_t outstandingTokenLimit = 10000; | 48 static const size_t outstandingTokenLimit = 10000; |
| 49 | 49 |
| 50 // We limit our chucks to 1000 tokens, to make sure the main | 50 // We limit our chucks to 1000 tokens, to make sure the main |
| 51 // thread is never waiting on the parser thread for tokens. | 51 // thread is never waiting on the parser thread for tokens. |
| 52 // This was tuned in https://bugs.webkit.org/show_bug.cgi?id=110408. | 52 // This was tuned in https://bugs.webkit.org/show_bug.cgi?id=110408. |
| 53 static const size_t pendingTokenLimit = 1000; | 53 static const size_t pendingTokenLimit = 1000; |
| 54 | 54 |
| 55 using namespace HTMLNames; | 55 using namespace HTMLNames; |
| 56 | 56 |
| 57 #ifndef NDEBUG | 57 #if ENABLE(ASSERT) |
| 58 | 58 |
| 59 static void checkThatTokensAreSafeToSendToAnotherThread(const CompactHTMLTokenSt
ream* tokens) | 59 static void checkThatTokensAreSafeToSendToAnotherThread(const CompactHTMLTokenSt
ream* tokens) |
| 60 { | 60 { |
| 61 for (size_t i = 0; i < tokens->size(); ++i) | 61 for (size_t i = 0; i < tokens->size(); ++i) |
| 62 ASSERT(tokens->at(i).isSafeToSendToAnotherThread()); | 62 ASSERT(tokens->at(i).isSafeToSendToAnotherThread()); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void checkThatPreloadsAreSafeToSendToAnotherThread(const PreloadRequestSt
ream& preloads) | 65 static void checkThatPreloadsAreSafeToSendToAnotherThread(const PreloadRequestSt
ream& preloads) |
| 66 { | 66 { |
| 67 for (size_t i = 0; i < preloads.size(); ++i) | 67 for (size_t i = 0; i < preloads.size(); ++i) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 break; | 232 break; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 void BackgroundHTMLParser::sendTokensToMainThread() | 237 void BackgroundHTMLParser::sendTokensToMainThread() |
| 238 { | 238 { |
| 239 if (m_pendingTokens->isEmpty()) | 239 if (m_pendingTokens->isEmpty()) |
| 240 return; | 240 return; |
| 241 | 241 |
| 242 #ifndef NDEBUG | 242 #if ENABLE(ASSERT) |
| 243 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); | 243 checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get()); |
| 244 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads); | 244 checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads); |
| 245 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos); | 245 checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos); |
| 246 #endif | 246 #endif |
| 247 | 247 |
| 248 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); | 248 OwnPtr<HTMLDocumentParser::ParsedChunk> chunk = adoptPtr(new HTMLDocumentPar
ser::ParsedChunk); |
| 249 chunk->preloads.swap(m_pendingPreloads); | 249 chunk->preloads.swap(m_pendingPreloads); |
| 250 chunk->xssInfos.swap(m_pendingXSSInfos); | 250 chunk->xssInfos.swap(m_pendingXSSInfos); |
| 251 chunk->tokenizerState = m_tokenizer->state(); | 251 chunk->tokenizerState = m_tokenizer->state(); |
| 252 chunk->treeBuilderState = m_treeBuilderSimulator.state(); | 252 chunk->treeBuilderState = m_treeBuilderSimulator.state(); |
| 253 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); | 253 chunk->inputCheckpoint = m_input.createCheckpoint(m_pendingTokens->size()); |
| 254 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); | 254 chunk->preloadScannerCheckpoint = m_preloadScanner->createCheckpoint(); |
| 255 chunk->tokens = m_pendingTokens.release(); | 255 chunk->tokens = m_pendingTokens.release(); |
| 256 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); | 256 callOnMainThread(bind(&HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser, m_parser, chunk.release())); |
| 257 | 257 |
| 258 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); | 258 m_pendingTokens = adoptPtr(new CompactHTMLTokenStream); |
| 259 } | 259 } |
| 260 | 260 |
| 261 } | 261 } |
| OLD | NEW |