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

Side by Side Diff: third_party/WebKit/Source/platform/SharedBuffer.h

Issue 2918443003: Remove redundant reading and writing of data about SharedBuffer.
Patch Set: benchmark Created 3 years, 6 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
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26
27 #ifndef SharedBuffer_h 26 #ifndef SharedBuffer_h
28 #define SharedBuffer_h 27 #define SharedBuffer_h
29 28
29 #include <atomic>
30
30 #include "platform/PlatformExport.h" 31 #include "platform/PlatformExport.h"
32 #include "platform/SharedBufferStep.h"
31 #include "platform/wtf/Forward.h" 33 #include "platform/wtf/Forward.h"
32 #include "platform/wtf/RefCounted.h" 34 #include "platform/wtf/RefCounted.h"
35 #include "platform/wtf/ThreadingPrimitives.h"
33 #include "platform/wtf/Vector.h" 36 #include "platform/wtf/Vector.h"
34 #include "platform/wtf/text/WTFString.h" 37 #include "platform/wtf/text/WTFString.h"
35 #include "third_party/skia/include/core/SkData.h" 38 #include "third_party/skia/include/core/SkData.h"
36 39
37 namespace blink { 40 namespace blink {
38 41
39 class WebProcessMemoryDump; 42 class WebProcessMemoryDump;
40 43
41 class PLATFORM_EXPORT SharedBuffer : public RefCounted<SharedBuffer> { 44 class PLATFORM_EXPORT SharedBuffer : public RefCounted<SharedBuffer> {
42 public: 45 public:
(...skipping 20 matching lines...) Expand all
63 static PassRefPtr<SharedBuffer> Create(const unsigned char* data, 66 static PassRefPtr<SharedBuffer> Create(const unsigned char* data,
64 STRICTLY_TYPED_ARG(size)) { 67 STRICTLY_TYPED_ARG(size)) {
65 STRICT_ARG_TYPE(size_t); 68 STRICT_ARG_TYPE(size_t);
66 return AdoptRef(new SharedBuffer(data, size)); 69 return AdoptRef(new SharedBuffer(data, size));
67 } 70 }
68 71
69 static PassRefPtr<SharedBuffer> AdoptVector(Vector<char>&); 72 static PassRefPtr<SharedBuffer> AdoptVector(Vector<char>&);
70 73
71 ~SharedBuffer(); 74 ~SharedBuffer();
72 75
76 class ThreadSafeStepper : public ThreadSafeRefCounted<ThreadSafeStepper> {
77 public:
78 PassRefPtr<SharedBufferStep> current_step();
79 ~ThreadSafeStepper();
80
81 private:
82 static PassRefPtr<ThreadSafeStepper> Create(
83 PassRefPtr<SharedBufferStep> step) {
84 return AdoptRef(new ThreadSafeStepper(std::move(step)));
85 }
86
87 ThreadSafeStepper(PassRefPtr<SharedBufferStep>);
88
89 void set_current_step(PassRefPtr<SharedBufferStep>);
90
91 struct Steps {
92 Steps();
93
94 static const size_t kStepArraySize = 5;
95 struct StepHolder {
96 RefPtr<SharedBufferStep> step;
97 bool self_keep;
98 bool keep_ref;
99 std::atomic<size_t> keep_count;
100 };
101 StepHolder step_holder_arr[kStepArraySize];
102
103 Steps* next;
104 };
105
106 void ClearStepHolderSelfKeep(Steps::StepHolder*);
107 void ClearStepHolder(Steps::StepHolder*);
108
109 Steps* steps_head_;
110 Steps* steps_tail_;
111 Steps* steps_to_write_;
112 size_t to_write_index_;
113 Steps::StepHolder* step_holder_to_read_;
114
115 friend class SharedBuffer;
116 };
117
118 PassRefPtr<ThreadSafeStepper> thread_safe_stepper() const;
119
73 // DEPRECATED: use a segment iterator or Copy() instead. 120 // DEPRECATED: use a segment iterator or Copy() instead.
74 // 121 //
75 // Calling this function will force internal segmented buffers to be merged 122 // Calling this function will force internal segmented buffers to be merged
76 // into a flat buffer. Use getSomeData() whenever possible for better 123 // into a flat buffer. Use getSomeData() whenever possible for better
77 // performance. 124 // performance.
78 const char* Data() const; 125 const char* Data() const;
79 126
80 size_t size() const; 127 size_t size() const;
81 128
82 bool IsEmpty() const { return !size(); } 129 bool IsEmpty() const { return !size(); }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 pos += length; 189 pos += length;
143 } 190 }
144 } 191 }
145 192
146 private: 193 private:
147 SharedBuffer(); 194 SharedBuffer();
148 explicit SharedBuffer(size_t); 195 explicit SharedBuffer(size_t);
149 SharedBuffer(const char*, size_t); 196 SharedBuffer(const char*, size_t);
150 SharedBuffer(const unsigned char*, size_t); 197 SharedBuffer(const unsigned char*, size_t);
151 198
152 // See SharedBuffer::data().
153 void MergeSegmentsIntoBuffer() const;
154
155 void AppendInternal(const char* data, size_t); 199 void AppendInternal(const char* data, size_t);
156 bool GetBytesInternal(void* dest, size_t) const; 200 bool GetBytesInternal(void* dest, size_t) const;
157 size_t GetSomeDataInternal(const char*& data, size_t position) const; 201 size_t GetSomeDataInternal(const char*& data, size_t position) const;
158 202
159 size_t size_; 203 void SynchronizeStepWithThreadStepper() const;
160 mutable Vector<char> buffer_; 204 bool forward_step_if_needed() const { return thread_safe_stepper_.Get(); }
161 mutable Vector<char*> segments_; 205
206 mutable RefPtr<SharedBufferStep> current_step_;
207 mutable RefPtr<ThreadSafeStepper> thread_safe_stepper_;
162 }; 208 };
163 209
164 } // namespace blink 210 } // namespace blink
165 211
166 #endif // SharedBuffer_h 212 #endif // SharedBuffer_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/BUILD.gn ('k') | third_party/WebKit/Source/platform/SharedBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698