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