Chromium Code Reviews| Index: Source/platform/SharedBuffer.cpp |
| diff --git a/Source/platform/SharedBuffer.cpp b/Source/platform/SharedBuffer.cpp |
| index 62065bcf6d3697bc032bb9062e39b16c921b1eb1..72650e6e55bb5d87e561146ec200a1277328d274 100644 |
| --- a/Source/platform/SharedBuffer.cpp |
| +++ b/Source/platform/SharedBuffer.cpp |
| @@ -40,22 +40,20 @@ |
| namespace blink { |
| -static const unsigned segmentSize = 0x1000; |
| -static const unsigned segmentPositionMask = 0x0FFF; |
| - |
| static inline unsigned segmentIndex(unsigned position) |
| { |
| - return position / segmentSize; |
| + return position / SharedBuffer::kSegmentSize; |
| } |
| static inline unsigned offsetInSegment(unsigned position) |
| { |
| + const unsigned segmentPositionMask = SharedBuffer::kSegmentSize - 1; |
| return position & segmentPositionMask; |
|
Peter Kasting
2015/03/25 19:53:11
This will be safer if you do:
return position %
|
| } |
| static inline char* allocateSegment() |
| { |
| - return static_cast<char*>(fastMalloc(segmentSize)); |
| + return static_cast<char*>(fastMalloc(SharedBuffer::kSegmentSize)); |
| } |
| static inline void freeSegment(char* p) |
| @@ -247,7 +245,7 @@ void SharedBuffer::append(const char* data, unsigned length) |
| unsigned positionInSegment = offsetInSegment(m_size - m_buffer.size()); |
| m_size += length; |
| - if (m_size <= segmentSize) { |
| + if (m_size <= kSegmentSize) { |
| // No need to use segments for small resource data. |
| m_buffer.append(data, length); |
| return; |
| @@ -260,7 +258,7 @@ void SharedBuffer::append(const char* data, unsigned length) |
| } else |
| segment = m_segments.last() + positionInSegment; |
| - unsigned segmentFreeSpace = segmentSize - positionInSegment; |
| + unsigned segmentFreeSpace = kSegmentSize - positionInSegment; |
| unsigned bytesToCopy = std::min(length, segmentFreeSpace); |
| for (;;) { |
| @@ -272,7 +270,7 @@ void SharedBuffer::append(const char* data, unsigned length) |
| data += bytesToCopy; |
| segment = allocateSegment(); |
| m_segments.append(segment); |
| - bytesToCopy = std::min(length, segmentSize); |
| + bytesToCopy = std::min(length, kSegmentSize); |
| } |
| } |
| @@ -315,7 +313,7 @@ void SharedBuffer::mergeSegmentsIntoBuffer() const |
| if (m_size > bufferSize) { |
| unsigned bytesLeft = m_size - bufferSize; |
| for (unsigned i = 0; i < m_segments.size(); ++i) { |
| - unsigned bytesToCopy = std::min(bytesLeft, segmentSize); |
| + unsigned bytesToCopy = std::min(bytesLeft, kSegmentSize); |
| m_buffer.append(m_segments[i], bytesToCopy); |
| bytesLeft -= bytesToCopy; |
| freeSegment(m_segments[i]); |
| @@ -342,7 +340,7 @@ unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con |
| position -= consecutiveSize; |
| unsigned segments = m_segments.size(); |
| - unsigned maxSegmentedSize = segments * segmentSize; |
| + unsigned maxSegmentedSize = segments * kSegmentSize; |
| unsigned segment = segmentIndex(position); |
| if (segment < segments) { |
| unsigned bytesLeft = totalSize - consecutiveSize; |
| @@ -350,7 +348,7 @@ unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con |
| unsigned positionInSegment = offsetInSegment(position); |
| someData = m_segments[segment] + positionInSegment; |
| - return segment == segments - 1 ? segmentedSize - position : segmentSize - positionInSegment; |
| + return segment == segments - 1 ? segmentedSize - position : kSegmentSize - positionInSegment; |
| } |
| ASSERT_NOT_REACHED(); |
| return 0; |