Index: third_party/WebKit/Source/platform/SharedBuffer.cpp |
diff --git a/third_party/WebKit/Source/platform/SharedBuffer.cpp b/third_party/WebKit/Source/platform/SharedBuffer.cpp |
index c043163ba8562bff45e42c424c7604e130112522..ef20e4361a3b3283815c9aebbdeaf4b041f0d871 100644 |
--- a/third_party/WebKit/Source/platform/SharedBuffer.cpp |
+++ b/third_party/WebKit/Source/platform/SharedBuffer.cpp |
@@ -42,12 +42,12 @@ |
namespace blink { |
-static inline unsigned segmentIndex(unsigned position) |
+static inline size_t segmentIndex(size_t position) |
{ |
return position / SharedBuffer::kSegmentSize; |
} |
-static inline unsigned offsetInSegment(unsigned position) |
+static inline size_t offsetInSegment(size_t position) |
{ |
return position % SharedBuffer::kSegmentSize; |
} |
@@ -85,22 +85,22 @@ static bool sizeComparator(SharedBuffer* a, SharedBuffer* b) |
static CString snippetForBuffer(SharedBuffer* sharedBuffer) |
{ |
- const unsigned kMaxSnippetLength = 64; |
+ const size_t kMaxSnippetLength = 64; |
char* snippet = 0; |
- unsigned snippetLength = std::min(sharedBuffer->size(), kMaxSnippetLength); |
+ size_t snippetLength = std::min(sharedBuffer->size(), kMaxSnippetLength); |
CString result = CString::newUninitialized(snippetLength, snippet); |
const char* segment; |
- unsigned offset = 0; |
- while (unsigned segmentLength = sharedBuffer->getSomeData(segment, offset)) { |
- unsigned length = std::min(segmentLength, snippetLength - offset); |
+ size_t offset = 0; |
+ while (size_t segmentLength = sharedBuffer->getSomeDataInternal(segment, offset)) { |
+ size_t length = std::min(segmentLength, snippetLength - offset); |
memcpy(snippet + offset, segment, length); |
offset += segmentLength; |
if (offset >= snippetLength) |
break; |
} |
- for (unsigned i = 0; i < snippetLength; ++i) { |
+ for (size_t i = 0; i < snippetLength; ++i) { |
if (!isASCIIPrintable(snippet[i])) |
snippet[i] = '?'; |
} |
@@ -159,41 +159,33 @@ SharedBuffer::SharedBuffer(size_t size) |
#endif |
} |
-SharedBuffer::SharedBuffer(const char* data, int size) |
+SharedBuffer::SharedBuffer(const char* data, size_t size) |
: m_size(0) |
, m_buffer(PurgeableVector::NotPurgeable) |
{ |
- // FIXME: Use unsigned consistently, and check for invalid casts when calling into SharedBuffer from other code. |
- if (size < 0) |
- CRASH(); |
- |
- append(data, size); |
+ appendInternal(data, size); |
#ifdef SHARED_BUFFER_STATS |
didCreateSharedBuffer(this); |
#endif |
} |
-SharedBuffer::SharedBuffer(const char* data, unsigned size, PurgeableVector::PurgeableOption purgeable) |
+SharedBuffer::SharedBuffer(const char* data, size_t size, PurgeableVector::PurgeableOption purgeable) |
: m_size(0) |
, m_buffer(purgeable) |
{ |
- append(data, size); |
+ appendInternal(data, size); |
#ifdef SHARED_BUFFER_STATS |
didCreateSharedBuffer(this); |
#endif |
} |
-SharedBuffer::SharedBuffer(const unsigned char* data, int size) |
+SharedBuffer::SharedBuffer(const unsigned char* data, size_t size) |
: m_size(0) |
, m_buffer(PurgeableVector::NotPurgeable) |
{ |
- // FIXME: Use unsigned consistently, and check for invalid casts when calling into SharedBuffer from other code. |
- if (size < 0) |
- CRASH(); |
- |
- append(reinterpret_cast<const char*>(data), size); |
+ appendInternal(reinterpret_cast<const char*>(data), size); |
#ifdef SHARED_BUFFER_STATS |
didCreateSharedBuffer(this); |
@@ -217,7 +209,7 @@ PassRefPtr<SharedBuffer> SharedBuffer::adoptVector(Vector<char>& vector) |
return buffer.release(); |
} |
-unsigned SharedBuffer::size() const |
+size_t SharedBuffer::size() const |
{ |
return m_size; |
} |
@@ -232,20 +224,20 @@ void SharedBuffer::append(PassRefPtr<SharedBuffer> data) |
{ |
const char* segment; |
size_t position = 0; |
- while (size_t length = data->getSomeData(segment, position)) { |
+ while (size_t length = data->getSomeDataInternal(segment, position)) { |
append(segment, length); |
position += length; |
} |
} |
-void SharedBuffer::append(const char* data, unsigned length) |
+void SharedBuffer::appendInternal(const char* data, size_t length) |
{ |
ASSERT(isLocked()); |
if (!length) |
return; |
ASSERT(m_size >= m_buffer.size()); |
- unsigned positionInSegment = offsetInSegment(m_size - m_buffer.size()); |
+ size_t positionInSegment = offsetInSegment(m_size - m_buffer.size()); |
m_size += length; |
if (m_size <= kSegmentSize) { |
@@ -261,19 +253,19 @@ void SharedBuffer::append(const char* data, unsigned length) |
} else |
segment = m_segments.last() + positionInSegment; |
- unsigned segmentFreeSpace = kSegmentSize - positionInSegment; |
- unsigned bytesToCopy = std::min(length, segmentFreeSpace); |
+ size_t segmentFreeSpace = kSegmentSize - positionInSegment; |
+ size_t bytesToCopy = std::min(length, segmentFreeSpace); |
for (;;) { |
memcpy(segment, data, bytesToCopy); |
- if (static_cast<unsigned>(length) == bytesToCopy) |
+ if (length == bytesToCopy) |
break; |
length -= bytesToCopy; |
data += bytesToCopy; |
segment = allocateSegment(); |
m_segments.append(segment); |
- bytesToCopy = std::min(length, static_cast<unsigned>(kSegmentSize)); |
+ bytesToCopy = std::min(length, static_cast<size_t>(kSegmentSize)); |
} |
} |
@@ -284,7 +276,7 @@ void SharedBuffer::append(const Vector<char>& data) |
void SharedBuffer::clear() |
{ |
- for (unsigned i = 0; i < m_segments.size(); ++i) |
+ for (size_t i = 0; i < m_segments.size(); ++i) |
freeSegment(m_segments[i]); |
m_segments.clear(); |
@@ -300,8 +292,8 @@ PassRefPtr<SharedBuffer> SharedBuffer::copy() const |
clone->m_buffer.append(m_buffer.data(), m_buffer.size()); |
if (!m_segments.isEmpty()) { |
const char* segment = 0; |
- unsigned position = m_buffer.size(); |
- while (unsigned segmentSize = getSomeData(segment, position)) { |
+ size_t position = m_buffer.size(); |
+ while (size_t segmentSize = getSomeDataInternal(segment, position)) { |
clone->m_buffer.append(segment, segmentSize); |
position += segmentSize; |
} |
@@ -312,11 +304,11 @@ PassRefPtr<SharedBuffer> SharedBuffer::copy() const |
void SharedBuffer::mergeSegmentsIntoBuffer() const |
{ |
- unsigned bufferSize = m_buffer.size(); |
+ size_t bufferSize = m_buffer.size(); |
if (m_size > bufferSize) { |
- unsigned bytesLeft = m_size - bufferSize; |
- for (unsigned i = 0; i < m_segments.size(); ++i) { |
- unsigned bytesToCopy = std::min(bytesLeft, static_cast<unsigned>(kSegmentSize)); |
+ size_t bytesLeft = m_size - bufferSize; |
+ for (size_t i = 0; i < m_segments.size(); ++i) { |
+ size_t bytesToCopy = std::min(bytesLeft, static_cast<size_t>(kSegmentSize)); |
m_buffer.append(m_segments[i], bytesToCopy); |
bytesLeft -= bytesToCopy; |
freeSegment(m_segments[i]); |
@@ -325,31 +317,31 @@ void SharedBuffer::mergeSegmentsIntoBuffer() const |
} |
} |
-unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) const |
+size_t SharedBuffer::getSomeDataInternal(const char*& someData, size_t position) const |
{ |
ASSERT(isLocked()); |
- unsigned totalSize = size(); |
+ size_t totalSize = size(); |
if (position >= totalSize) { |
someData = 0; |
return 0; |
} |
ASSERT_WITH_SECURITY_IMPLICATION(position < m_size); |
- unsigned consecutiveSize = m_buffer.size(); |
+ size_t consecutiveSize = m_buffer.size(); |
if (position < consecutiveSize) { |
someData = m_buffer.data() + position; |
return consecutiveSize - position; |
} |
position -= consecutiveSize; |
- unsigned segments = m_segments.size(); |
- unsigned maxSegmentedSize = segments * kSegmentSize; |
- unsigned segment = segmentIndex(position); |
+ size_t segments = m_segments.size(); |
+ size_t maxSegmentedSize = segments * kSegmentSize; |
+ size_t segment = segmentIndex(position); |
if (segment < segments) { |
- unsigned bytesLeft = totalSize - consecutiveSize; |
- unsigned segmentedSize = std::min(maxSegmentedSize, bytesLeft); |
+ size_t bytesLeft = totalSize - consecutiveSize; |
+ size_t segmentedSize = std::min(maxSegmentedSize, bytesLeft); |
- unsigned positionInSegment = offsetInSegment(position); |
+ size_t positionInSegment = offsetInSegment(position); |
someData = m_segments[segment] + positionInSegment; |
return segment == segments - 1 ? segmentedSize - position : kSegmentSize - positionInSegment; |
} |
@@ -357,14 +349,14 @@ unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) con |
return 0; |
} |
-bool SharedBuffer::getAsBytes(void* dest, unsigned byteLength) const |
+bool SharedBuffer::getAsBytesInternal(void* dest, size_t byteLength) const |
{ |
if (!dest || byteLength != size()) |
return false; |
const char* segment = 0; |
- unsigned position = 0; |
- while (unsigned segmentSize = getSomeData(segment, position)) { |
+ size_t position = 0; |
+ while (size_t segmentSize = getSomeDataInternal(segment, position)) { |
memcpy(static_cast<char*>(dest) + position, segment, segmentSize); |
position += segmentSize; |
} |
@@ -380,12 +372,12 @@ bool SharedBuffer::getAsBytes(void* dest, unsigned byteLength) const |
PassRefPtr<SkData> SharedBuffer::getAsSkData() const |
{ |
- unsigned bufferLength = size(); |
+ size_t bufferLength = size(); |
SkData* data = SkData::NewUninitialized(bufferLength); |
char* buffer = static_cast<char*>(data->writable_data()); |
const char* segment = 0; |
- unsigned position = 0; |
- while (unsigned segmentSize = getSomeData(segment, position)) { |
+ size_t position = 0; |
+ while (size_t segmentSize = getSomeDataInternal(segment, position)) { |
memcpy(buffer + position, segment, segmentSize); |
position += segmentSize; |
} |