Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/ParsedChunkQueue.cpp

Issue 2181943002: Rename ParsedChunk to TokenizedChunk in core/html/parser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/html/parser/ParsedChunkQueue.h"
6
7 #include "platform/RuntimeEnabledFeatures.h"
8 #include <algorithm>
9 #include <memory>
10
11 namespace blink {
12
13 namespace {
14
15 // TODO(csharrison): Remove this temporary class when the ParseHTMLOnMainThread
16 // experiment ends.
17 class MaybeLocker {
18 public:
19 MaybeLocker(Mutex* mutex)
20 : m_mutex(mutex)
21 {
22 if (m_mutex)
23 m_mutex->lock();
24 }
25 ~MaybeLocker()
26 {
27 if (m_mutex)
28 m_mutex->unlock();
29 }
30
31 private:
32 Mutex* m_mutex;
33 };
34
35 } // namespace
36
37 ParsedChunkQueue::ParsedChunkQueue()
38 : m_mutex(RuntimeEnabledFeatures::parseHTMLOnMainThreadEnabled() ? nullptr : new Mutex)
39 {
40 }
41
42 ParsedChunkQueue::~ParsedChunkQueue()
43 {
44 }
45
46 bool ParsedChunkQueue::enqueue(std::unique_ptr<HTMLDocumentParser::ParsedChunk> chunk)
47 {
48 MaybeLocker locker(m_mutex.get());
49
50 m_pendingTokenCount += chunk->tokens->size();
51 m_peakPendingTokenCount = std::max(m_peakPendingTokenCount, m_pendingTokenCo unt);
52
53 bool wasEmpty = m_pendingChunks.isEmpty();
54 m_pendingChunks.append(std::move(chunk));
55 m_peakPendingChunkCount = std::max(m_peakPendingChunkCount, m_pendingChunks. size());
56
57 return wasEmpty;
58 }
59
60 void ParsedChunkQueue::clear()
61 {
62 MaybeLocker locker(m_mutex.get());
63
64 m_pendingTokenCount = 0;
65 m_pendingChunks.clear();
66 }
67
68 void ParsedChunkQueue::takeAll(Vector<std::unique_ptr<HTMLDocumentParser::Parsed Chunk>>& vector)
69 {
70 MaybeLocker locker(m_mutex.get());
71
72 ASSERT(vector.isEmpty());
73 m_pendingChunks.swap(vector);
74 }
75
76 size_t ParsedChunkQueue::peakPendingChunkCount()
77 {
78 MaybeLocker locker(m_mutex.get());
79 return m_peakPendingChunkCount;
80 }
81
82 size_t ParsedChunkQueue::peakPendingTokenCount()
83 {
84 MaybeLocker locker(m_mutex.get());
85 return m_peakPendingTokenCount;
86 }
87
88 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698