unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) const { unsigned totalSize = size(); if (position >= totalSize) { someData = 0; return 0; } #if ENABLE(DISK_IMAGE_CACHE) ASSERT(position < size()); if (isMemoryMapped()) { const char* data = static_cast<const char*>(diskImageCache().dataForItem(m_diskImageCacheId)); someData = data + position; return size() - position; } #endif if (hasPlatformData() || m_purgeableBuffer) { ASSERT_WITH_SECURITY_IMPLICATION(position < size()); someData = data() + position; return totalSize - position; } ASSERT_WITH_SECURITY_IMPLICATION(position < m_size); unsigned consecutiveSize = m_buffer->data.size(); if (position < consecutiveSize) { someData = m_buffer->data.data() + position; return consecutiveSize - position; } position -= consecutiveSize; #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK) unsigned segments = m_segments.size(); unsigned maxSegmentedSize = segments * segmentSize; unsigned segment = segmentIndex(position); if (segment < segments) { unsigned bytesLeft = totalSize - consecutiveSize; unsigned segmentedSize = std::min(maxSegmentedSize, bytesLeft); unsigned positionInSegment = offsetInSegment(position); someData = m_segments[segment] + positionInSegment; return segment == segments - 1 ? segmentedSize - position : segmentSize - positionInSegment; } ASSERT_NOT_REACHED(); return 0; #else return copySomeDataFromDataArray(someData, position); #endif }
unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) const { unsigned totalSize = size(); if (position >= totalSize) { someData = 0; return 0; } if (hasPlatformData() || m_purgeableBuffer) { ASSERT(position < size()); someData = data() + position; return totalSize - position; } ASSERT(position < m_size); unsigned 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 * segmentSize; unsigned segment = segmentIndex(position); if (segment < segments) { unsigned bytesLeft = totalSize - consecutiveSize; unsigned segmentedSize = min(maxSegmentedSize, bytesLeft); unsigned positionInSegment = offsetInSegment(position); someData = m_segments[segment] + positionInSegment; return segment == segments - 1 ? segmentedSize - position : segmentSize - positionInSegment; } #if HAVE(NETWORK_CFDATA_ARRAY_CALLBACK) ASSERT(maxSegmentedSize <= position); position -= maxSegmentedSize; return copySomeDataFromDataArray(someData, position); #else ASSERT_NOT_REACHED(); return 0; #endif }
unsigned SharedBuffer::getSomeData(const char*& someData, unsigned position) const { unsigned totalSize = size(); if (position >= totalSize) { someData = 0; return 0; } if (hasPlatformData()) { ASSERT_WITH_SECURITY_IMPLICATION(position < size()); someData = data() + position; return totalSize - position; } ASSERT_WITH_SECURITY_IMPLICATION(position < m_size); unsigned consecutiveSize = m_buffer->data.size(); if (position < consecutiveSize) { someData = m_buffer->data.data() + position; return consecutiveSize - position; } position -= consecutiveSize; #if !USE(NETWORK_CFDATA_ARRAY_CALLBACK) unsigned segments = m_segments.size(); unsigned maxSegmentedSize = segments * segmentSize; unsigned segment = segmentIndex(position); if (segment < segments) { unsigned bytesLeft = totalSize - consecutiveSize; unsigned segmentedSize = std::min(maxSegmentedSize, bytesLeft); unsigned positionInSegment = offsetInSegment(position); someData = m_segments[segment] + positionInSegment; return segment == segments - 1 ? segmentedSize - position : segmentSize - positionInSegment; } ASSERT_NOT_REACHED(); return 0; #else return copySomeDataFromDataArray(someData, position); #endif }