move common code into shared helper function

git-svn-id: http://skia.googlecode.com/svn/trunk@1718 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-06-24 20:06:36 +00:00
parent 1ca4f26039
commit 67d0cff9ac

View File

@ -255,6 +255,14 @@ size_t SkFILEStream::read(void* buffer, size_t size)
///////////////////////////////////////////////////////////////////////////////
static SkData* newFromParams(const void* src, size_t size, bool copyData) {
if (copyData) {
return SkData::NewWithCopy(src, size);
} else {
return SkData::NewWithProc(src, size, NULL, NULL);
}
}
SkMemoryStream::SkMemoryStream() {
fData = SkData::NewEmpty();
fOffset = 0;
@ -266,11 +274,7 @@ SkMemoryStream::SkMemoryStream(size_t size) {
}
SkMemoryStream::SkMemoryStream(const void* src, size_t size, bool copyData) {
if (copyData) {
fData = SkData::NewWithCopy(src, size);
} else {
fData = SkData::NewWithProc(src, size, NULL, NULL);
}
fData = newFromParams(src, size, copyData);
fOffset = 0;
}
@ -286,11 +290,7 @@ void SkMemoryStream::setMemoryOwned(const void* src, size_t size) {
void SkMemoryStream::setMemory(const void* src, size_t size, bool copyData) {
fData->unref();
if (copyData) {
fData = SkData::NewWithCopy(src, size);
} else {
fData = SkData::NewWithProc(src, size, NULL, NULL);
}
fData = newFromParams(src, size, copyData);
fOffset = 0;
}