Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: third_party/WebKit/Source/platform/SharedBuffer.cpp

Issue 2249533003: [Platform] Enable to get a partial data of SharedBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 02006e7a8524b17776d8169fec914f4cc4eebf4f..6ce6466b54320d0db0037e446ea4c78f831d7dcc 100644
--- a/third_party/WebKit/Source/platform/SharedBuffer.cpp
+++ b/third_party/WebKit/Source/platform/SharedBuffer.cpp
@@ -240,25 +240,27 @@ size_t SharedBuffer::getSomeDataInternal(const char*& someData, size_t position)
return 0;
}
-bool SharedBuffer::getAsBytesInternal(void* dest, size_t byteLength) const
+bool SharedBuffer::getAsBytesInternal(void* dest, size_t loadPosition, size_t byteLength) const
{
- if (!dest || byteLength != size())
+ if (!dest)
return false;
- const char* segment = 0;
- size_t position = 0;
- while (size_t segmentSize = getSomeDataInternal(segment, position)) {
- memcpy(static_cast<char*>(dest) + position, segment, segmentSize);
- position += segmentSize;
- }
+ const char* segment = nullptr;
+ size_t writePosition = 0;
+ while (byteLength > 0) {
+ size_t loadSize = getSomeDataInternal(segment, loadPosition);
+ if (loadSize == 0)
+ break;
- if (position != byteLength) {
- ASSERT_NOT_REACHED();
- // Don't return the incomplete data.
- return false;
+ if (byteLength < loadSize)
+ loadSize = byteLength;
+ memcpy(static_cast<char*>(dest) + writePosition, segment, loadSize);
+ loadPosition += loadSize;
+ writePosition += loadSize;
+ byteLength -= loadSize;
}
- return true;
+ return byteLength == 0;
}
sk_sp<SkData> SharedBuffer::getAsSkData() const
« no previous file with comments | « third_party/WebKit/Source/platform/SharedBuffer.h ('k') | third_party/WebKit/Source/platform/SharedBufferTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698