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 23 matching lines...) Expand all Loading... |
34 namespace blink { | 34 namespace blink { |
35 | 35 |
36 FastSharedBufferReader::FastSharedBufferReader(PassRefPtr<SharedBuffer> data) | 36 FastSharedBufferReader::FastSharedBufferReader(PassRefPtr<SharedBuffer> data) |
37 : m_data(data) | 37 : m_data(data) |
38 , m_segment(0) | 38 , m_segment(0) |
39 , m_segmentLength(0) | 39 , m_segmentLength(0) |
40 , m_dataPosition(0) | 40 , m_dataPosition(0) |
41 { | 41 { |
42 } | 42 } |
43 | 43 |
44 void FastSharedBufferReader::setData(PassRefPtr<SharedBuffer> data) | |
45 { | |
46 if (data == m_data) | |
47 return; | |
48 m_data = data; | |
49 m_segment = 0; | |
50 m_segmentLength = 0; | |
51 m_dataPosition = 0; | |
52 } | |
53 | |
54 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size
_t length, char* buffer) const | 44 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size
_t length, char* buffer) const |
55 { | 45 { |
56 RELEASE_ASSERT(dataPosition + length <= m_data->size()); | 46 RELEASE_ASSERT(dataPosition + length <= m_data->size()); |
57 | 47 |
58 // Use the cached segment if it can serve the request. | 48 // Use the cached segment if it can serve the request. |
59 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) | 49 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) |
60 return m_segment + dataPosition - m_dataPosition; | 50 return m_segment + dataPosition - m_dataPosition; |
61 | 51 |
62 // Return a pointer into |m_data| if the request doesn't span segments. | 52 // Return a pointer into |m_data| if the request doesn't span segments. |
63 getSomeDataInternal(dataPosition); | 53 getSomeDataInternal(dataPosition); |
(...skipping 21 matching lines...) Expand all Loading... |
85 } | 75 } |
86 | 76 |
87 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) const | 77 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) const |
88 { | 78 { |
89 m_dataPosition = dataPosition; | 79 m_dataPosition = dataPosition; |
90 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); | 80 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); |
91 ASSERT(m_segmentLength); | 81 ASSERT(m_segmentLength); |
92 } | 82 } |
93 | 83 |
94 } // namespace blink | 84 } // namespace blink |
OLD | NEW |