| 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 |
| 44 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) |
| 45 { | 55 { |
| 46 RELEASE_ASSERT(dataPosition + length <= m_data->size()); | 56 RELEASE_ASSERT(dataPosition + length <= m_data->size()); |
| 47 | 57 |
| 48 // Use the cached segment if it can serve the request. | 58 // Use the cached segment if it can serve the request. |
| 49 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) | 59 if (dataPosition >= m_dataPosition && dataPosition + length <= m_dataPositio
n + m_segmentLength) |
| 50 return m_segment + dataPosition - m_dataPosition; | 60 return m_segment + dataPosition - m_dataPosition; |
| 51 | 61 |
| 52 // 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. |
| 53 getSomeDataInternal(dataPosition); | 63 getSomeDataInternal(dataPosition); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 75 } | 85 } |
| 76 | 86 |
| 77 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) | 87 void FastSharedBufferReader::getSomeDataInternal(unsigned dataPosition) |
| 78 { | 88 { |
| 79 m_dataPosition = dataPosition; | 89 m_dataPosition = dataPosition; |
| 80 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); | 90 m_segmentLength = m_data->getSomeData(m_segment, dataPosition); |
| 81 ASSERT(m_segmentLength); | 91 ASSERT(m_segmentLength); |
| 82 } | 92 } |
| 83 | 93 |
| 84 } // namespace blink | 94 } // namespace blink |
| OLD | NEW |