| 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/ParsedChunkQueue.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 7 #include <memory> | 8 #include <memory> |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 ParsedChunkQueue::ParsedChunkQueue() | 12 ParsedChunkQueue::ParsedChunkQueue() |
| 12 { | 13 { |
| 13 } | 14 } |
| 14 | 15 |
| 15 ParsedChunkQueue::~ParsedChunkQueue() | 16 ParsedChunkQueue::~ParsedChunkQueue() |
| 16 { | 17 { |
| 17 } | 18 } |
| 18 | 19 |
| 19 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk>
chunk) | 20 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk>
chunk) |
| 20 { | 21 { |
| 21 MutexLocker locker(m_mutex); | 22 MutexLocker locker(m_mutex); |
| 22 | 23 |
| 24 m_pendingTokenCount += chunk->tokens->size(); |
| 25 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo
unt); |
| 26 |
| 23 bool wasEmpty = m_pendingChunks.isEmpty(); | 27 bool wasEmpty = m_pendingChunks.isEmpty(); |
| 24 m_pendingChunks.append(std::move(chunk)); | 28 m_pendingChunks.append(std::move(chunk)); |
| 29 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks.
size()); |
| 30 |
| 25 return wasEmpty; | 31 return wasEmpty; |
| 26 } | 32 } |
| 27 | 33 |
| 28 void ParsedChunkQueue::clear() | 34 void ParsedChunkQueue::clear() |
| 29 { | 35 { |
| 30 MutexLocker locker(m_mutex); | 36 MutexLocker locker(m_mutex); |
| 31 | 37 |
| 38 m_pendingTokenCount = 0; |
| 32 m_pendingChunks.clear(); | 39 m_pendingChunks.clear(); |
| 33 } | 40 } |
| 34 | 41 |
| 35 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed
Chunk>>& vector) | 42 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed
Chunk>>& vector) |
| 36 { | 43 { |
| 37 MutexLocker locker(m_mutex); | 44 MutexLocker locker(m_mutex); |
| 38 | 45 |
| 39 ASSERT(vector.isEmpty()); | 46 ASSERT(vector.isEmpty()); |
| 40 m_pendingChunks.swap(vector); | 47 m_pendingChunks.swap(vector); |
| 41 } | 48 } |
| 42 | 49 |
| 50 size_t ParsedChunkQueue::peakPendingChunkCount() |
| 51 { |
| 52 MutexLocker locker(m_mutex); |
| 53 return m_peakPendingChunkCount; |
| 54 } |
| 55 |
| 56 size_t ParsedChunkQueue::peakPendingTokenCount() |
| 57 { |
| 58 MutexLocker locker(m_mutex); |
| 59 return m_peakPendingTokenCount; |
| 60 } |
| 61 |
| 43 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |