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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void FastSharedBufferReader::setData(PassRefPtr<SharedBuffer> data) | 44 void FastSharedBufferReader::setData(PassRefPtr<SharedBuffer> data) |
45 { | 45 { |
46 if (data == m_data) | 46 if (data == m_data) |
47 return; | 47 return; |
48 m_data = data; | 48 m_data = data; |
49 m_segment = 0; | 49 m_segment = 0; |
50 m_segmentLength = 0; | 50 m_segmentLength = 0; |
51 m_dataPosition = 0; | 51 m_dataPosition = 0; |
52 } | 52 } |
53 | 53 |
54 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size
_t length, char* buffer) | 54 const char* FastSharedBufferReader::getConsecutiveData(size_t dataPosition, size
_t length, char* buffer) const |
55 { | 55 { |
56 RELEASE_ASSERT(dataPosition + length <= m_data->size()); | 56 RELEASE_ASSERT(dataPosition + length <= m_data->size()); |
57 | 57 |
58 // Use the cached segment if it can serve the request. | 58 // Use the cached segment if it can serve the request. |
59 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) | 59 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) |
60 return m_segment + dataPosition - m_dataPosition; | 60 return m_segment + dataPosition - m_dataPosition; |
61 | 61 |
62 // Return a pointer into |m_data| if the request doesn't span segments. | 62 // Return a pointer into |m_data| if the request doesn't span segments. |
63 getSomeDataInternal(dataPosition); | 63 getSomeDataInternal(dataPosition); |
64 if (length <= m_segmentLength) | 64 if (length <= m_segmentLength) |
65 return m_segment; | 65 return m_segment; |
66 | 66 |
67 for (char* dest = buffer; ; ) { | 67 for (char* dest = buffer; ; ) { |
68 size_t copy = std::min(length, m_segmentLength); | 68 size_t copy = std::min(length, m_segmentLength); |
69 memcpy(dest, m_segment, copy); | 69 memcpy(dest, m_segment, copy); |
70 length -= copy; | 70 length -= copy; |
71 if (!length) | 71 if (!length) |
72 return buffer; | 72 return buffer; |
73 | 73 |
74 // Continue reading the next segment. | 74 // Continue reading the next segment. |
75 dest += copy; | 75 dest += copy; |
76 getSomeDataInternal(m_dataPosition + copy); | 76 getSomeDataInternal(m_dataPosition + copy); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 size_t FastSharedBufferReader::getSomeData(const char*& someData, size_t dataPos
ition) | 80 size_t FastSharedBufferReader::getSomeData(const char*& someData, size_t dataPos
ition) const |
81 { | 81 { |
82 getSomeDataInternal(dataPosition); | 82 getSomeDataInternal(dataPosition); |
83 someData = m_segment; | 83 someData = m_segment; |
84 return m_segmentLength; | 84 return m_segmentLength; |
85 } | 85 } |
86 | 86 |
87 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) | 87 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) const |
88 { | 88 { |
89 m_dataPosition = dataPosition; | 89 m_dataPosition = dataPosition; |
90 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); | 90 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); |
91 ASSERT(m_segmentLength); | 91 ASSERT(m_segmentLength); |
92 } | 92 } |
93 | 93 |
94 } // namespace blink | 94 } // namespace blink |
OLD | NEW |