aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-01-29 12:03:53 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-29 12:03:53 -0800
commit4f358fc269077219c18f30f4752e3678a15c222a (patch)
tree39640dc32fb95eefc5b56e5bc28b35d16ab8bf55 /src
parent648238cc900994de79c9e7d17f755661222aa52f (diff)
Make SkWriter32::snapshotAsData() a dumb copy.
SkWriter32::snapshotAsData() is no longer performance critical. It's only used when we're serializing to disk. BUG=skia:2289 Review URL: https://codereview.chromium.org/875403005
Diffstat (limited to 'src')
-rw-r--r--src/core/SkWriter32.cpp26
1 files changed, 1 insertions, 25 deletions
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 00c46368b6..a1a8b8800a 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -74,32 +74,8 @@ void SkWriter32::growToAtLeast(size_t size) {
// we were external, so copy in the data
memcpy(fData, fExternal, fUsed);
}
- // Invalidate the snapshot, we know it is no longer useful.
- fSnapshot.reset(NULL);
}
SkData* SkWriter32::snapshotAsData() const {
- // get a non const version of this, we are only conceptually const
- SkWriter32& mutable_this = *const_cast<SkWriter32*>(this);
- // we use size change detection to invalidate the cached data
- if ((fSnapshot.get() != NULL) && (fSnapshot->size() != fUsed)) {
- mutable_this.fSnapshot.reset(NULL);
- }
- if (fSnapshot.get() == NULL) {
- uint8_t* buffer = NULL;
- if ((fExternal != NULL) && (fData == fExternal)) {
- // We need to copy to an allocated buffer before returning.
- buffer = (uint8_t*)sk_malloc_throw(fUsed);
- memcpy(buffer, fData, fUsed);
- } else {
- buffer = mutable_this.fInternal.detach();
- // prepare us to do copy on write, by pretending the data buffer
- // is external and size limited
- mutable_this.fData = buffer;
- mutable_this.fCapacity = fUsed;
- mutable_this.fExternal = buffer;
- }
- mutable_this.fSnapshot.reset(SkData::NewFromMalloc(buffer, fUsed));
- }
- return SkRef(fSnapshot.get()); // Take an extra ref for the caller.
+ return SkData::NewWithCopy(fData, fUsed);
}