| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/parser/ParsedChunkQueue.h" | 5 #include "core/html/parser/TokenizedChunkQueue.h" |
| 6 | 6 |
| 7 #include "platform/RuntimeEnabledFeatures.h" | 7 #include "platform/RuntimeEnabledFeatures.h" |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 // TODO(csharrison): Remove this temporary class when the ParseHTMLOnMainThread | 15 // TODO(csharrison): Remove this temporary class when the ParseHTMLOnMainThread |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 if (m_mutex) | 27 if (m_mutex) |
| 28 m_mutex->unlock(); | 28 m_mutex->unlock(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 Mutex* m_mutex; | 32 Mutex* m_mutex; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 ParsedChunkQueue::ParsedChunkQueue() | 37 TokenizedChunkQueue::TokenizedChunkQueue() |
| 38 : m_mutex(RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled() ? nullptr :
new Mutex) | 38 : m_mutex(RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled() ? nullptr :
new Mutex) |
| 39 { | 39 { |
| 40 } | 40 } |
| 41 | 41 |
| 42 ParsedChunkQueue::~ParsedChunkQueue() | 42 TokenizedChunkQueue::~TokenizedChunkQueue() |
| 43 { | 43 { |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk>
chunk) | 46 bool TokenizedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::TokenizedC
hunk> chunk) |
| 47 { | 47 { |
| 48 MaybeLocker locker(m_mutex.get()); | 48 MaybeLocker locker(m_mutex.get()); |
| 49 | 49 |
| 50 m_pendingTokenCount += chunk->tokens->size(); | 50 m_pendingTokenCount += chunk->tokens->size(); |
| 51 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo
unt); | 51 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo
unt); |
| 52 | 52 |
| 53 bool wasEmpty = m_pendingChunks.isEmpty(); | 53 bool wasEmpty = m_pendingChunks.isEmpty(); |
| 54 m_pendingChunks.append(std::move(chunk)); | 54 m_pendingChunks.append(std::move(chunk)); |
| 55 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks.
size()); | 55 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks.
size()); |
| 56 | 56 |
| 57 return wasEmpty; | 57 return wasEmpty; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ParsedChunkQueue::clear() | 60 void TokenizedChunkQueue::clear() |
| 61 { | 61 { |
| 62 MaybeLocker locker(m_mutex.get()); | 62 MaybeLocker locker(m_mutex.get()); |
| 63 | 63 |
| 64 m_pendingTokenCount = 0; | 64 m_pendingTokenCount = 0; |
| 65 m_pendingChunks.clear(); | 65 m_pendingChunks.clear(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed
Chunk>>& vector) | 68 void TokenizedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Tok
enizedChunk>>& vector) |
| 69 { | 69 { |
| 70 MaybeLocker locker(m_mutex.get()); | 70 MaybeLocker locker(m_mutex.get()); |
| 71 | 71 |
| 72 ASSERT(vector.isEmpty()); | 72 DCHECK(vector.isEmpty()); |
| 73 m_pendingChunks.swap(vector); | 73 m_pendingChunks.swap(vector); |
| 74 } | 74 } |
| 75 | 75 |
| 76 size_t ParsedChunkQueue::peakPendingChunkCount() | 76 size_t TokenizedChunkQueue::peakPendingChunkCount() |
| 77 { | 77 { |
| 78 MaybeLocker locker(m_mutex.get()); | 78 MaybeLocker locker(m_mutex.get()); |
| 79 return m_peakPendingChunkCount; | 79 return m_peakPendingChunkCount; |
| 80 } | 80 } |
| 81 | 81 |
| 82 size_t ParsedChunkQueue::peakPendingTokenCount() | 82 size_t TokenizedChunkQueue::peakPendingTokenCount() |
| 83 { | 83 { |
| 84 MaybeLocker locker(m_mutex.get()); | 84 MaybeLocker locker(m_mutex.get()); |
| 85 return m_peakPendingTokenCount; | 85 return m_peakPendingTokenCount; |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |