Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef FastSharedBufferReader_h | 31 #ifndef FastSharedBufferReader_h |
| 32 #define FastSharedBufferReader_h | 32 #define FastSharedBufferReader_h |
| 33 | 33 |
| 34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
| 35 #include "platform/SharedBuffer.h" | 35 #include "platform/image-decoders/SegmentReader.h" |
| 36 #include "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
| 37 #include "wtf/Noncopyable.h" | 37 #include "wtf/Noncopyable.h" |
| 38 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
| 39 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 // This class is used by image decoders to avoid memory consolidation and | 43 // This class is used by image decoders to avoid memory consolidation and |
| 44 // therefore minimizes the cost of memory copying when the decoders | 44 // therefore minimizes the cost of memory copying when the decoders |
| 45 // repeatedly read from a buffer that is continually growing due to network | 45 // repeatedly read from a buffer that is continually growing due to network |
| 46 // traffic. | 46 // traffic. |
| 47 class PLATFORM_EXPORT FastSharedBufferReader final { | 47 class PLATFORM_EXPORT FastSharedBufferReader final { |
| 48 DISALLOW_NEW(); | 48 DISALLOW_NEW(); |
| 49 WTF_MAKE_NONCOPYABLE(FastSharedBufferReader); | 49 WTF_MAKE_NONCOPYABLE(FastSharedBufferReader); |
| 50 public: | 50 public: |
| 51 FastSharedBufferReader(PassRefPtr<SharedBuffer> data); | 51 FastSharedBufferReader(PassRefPtr<SegmentReader> data); |
| 52 | 52 |
| 53 void setData(PassRefPtr<SharedBuffer>); | 53 void setData(PassRefPtr<SegmentReader>); |
| 54 | 54 |
| 55 // Returns a consecutive buffer that carries the data starting | 55 // Returns a consecutive buffer that carries the data starting |
| 56 // at |dataPosition| with |length| bytes. | 56 // at |dataPosition| with |length| bytes. |
| 57 // This method returns a pointer to a memory segment stored in | 57 // This method returns a pointer to a memory segment stored in |
| 58 // |m_data| if such a consecutive buffer can be found. | 58 // |m_data| if such a consecutive buffer can be found. |
| 59 // Otherwise copies into |buffer| and returns it. | 59 // Otherwise copies into |buffer| and returns it. |
| 60 // Caller must ensure there are enough bytes in |m_data| and |buffer|. | 60 // Caller must ensure there are enough bytes in |m_data| and |buffer|. |
| 61 const char* getConsecutiveData(size_t dataPosition, size_t length, char* buf fer) const; | 61 const char* getConsecutiveData(size_t dataPosition, size_t length, char* buf fer) const; |
| 62 | 62 |
| 63 // Wraps SharedBuffer::getSomeData(). | 63 // Wraps SegmentReader::getSomeData(). |
| 64 size_t getSomeData(const char*& someData, size_t dataPosition) const; | 64 size_t getSomeData(const char*& someData, size_t dataPosition) const; |
| 65 | 65 |
| 66 // Returns a byte at |dataPosition|. | 66 // Returns a byte at |dataPosition|. |
| 67 // Caller must ensure there are enough bytes in |m_data|. | 67 // Caller must ensure there are enough bytes in |m_data|. |
| 68 inline char getOneByte(size_t dataPosition) const | 68 inline char getOneByte(size_t dataPosition) const |
| 69 { | 69 { |
| 70 return *getConsecutiveData(dataPosition, 1, 0); | 70 return *getConsecutiveData(dataPosition, 1, 0); |
| 71 } | 71 } |
| 72 | 72 |
| 73 size_t size() const | 73 size_t size() const |
| 74 { | 74 { |
| 75 return m_data->size(); | 75 return m_data->size(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // This class caches the last access for faster subsequent reads. This | 78 // This class caches the last access for faster subsequent reads. This |
| 79 // method clears that cache in case the SharedBuffer has been modified | 79 // method clears that cache in case the SegmentReader has been modified |
|
scroggo_chromium
2016/03/22 20:18:42
This should still say SharedBuffer
scroggo_chromium
2016/03/24 13:59:45
Done.
| |
| 80 // (i.e. with mergeSegmentsIntoBuffer). | 80 // (i.e. with mergeSegmentsIntoBuffer). |
| 81 void clearCache(); | 81 void clearCache(); |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 void getSomeDataInternal(unsigned dataPosition) const; | 84 void getSomeDataInternal(unsigned dataPosition) const; |
| 85 | 85 |
| 86 RefPtr<SharedBuffer> m_data; | 86 RefPtr<SegmentReader> m_data; |
| 87 | 87 |
| 88 // Caches the last segment of |m_data| accessed, since subsequent reads are | 88 // Caches the last segment of |m_data| accessed, since subsequent reads are |
| 89 // likely to re-access it. | 89 // likely to re-access it. |
| 90 mutable const char* m_segment; | 90 mutable const char* m_segment; |
| 91 mutable size_t m_segmentLength; | 91 mutable size_t m_segmentLength; |
| 92 | 92 |
| 93 // Data position in |m_data| pointed to by |m_segment|. | 93 // Data position in |m_data| pointed to by |m_segment|. |
| 94 mutable size_t m_dataPosition; | 94 mutable size_t m_dataPosition; |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // namespace blink | 97 } // namespace blink |
| 98 | 98 |
| 99 #endif | 99 #endif |
| OLD | NEW |