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

Unified Diff: src/core/SkData.cpp

Issue 132803005: SkOnce: add option to call another cleanup function once at exit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add static Created 6 years, 11 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
« no previous file with comments | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkData.cpp
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp
index fd963a9ff50b22aedf2d18f30ee6880e08afd598..176e93c47be2f98303ba849cbb0eda597d370e6c 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -48,16 +48,18 @@ size_t SkData::copyRange(size_t offset, size_t length, void* buffer) const {
///////////////////////////////////////////////////////////////////////////////
-void SkData::NewEmptyImpl(SkData** empty) {
- *empty = new SkData(NULL, 0, NULL, NULL);
+static SkData* gEmptyDataRef = NULL;
+static void cleanup_gEmptyDataRef() { gEmptyDataRef->unref(); }
+
+void SkData::NewEmptyImpl(int) {
+ gEmptyDataRef = new SkData(NULL, 0, NULL, NULL);
}
SkData* SkData::NewEmpty() {
- static SkData* gEmptyRef;
SK_DECLARE_STATIC_ONCE(once);
- SkOnce(&once, SkData::NewEmptyImpl, &gEmptyRef);
- gEmptyRef->ref();
- return gEmptyRef;
+ SkOnce(&once, SkData::NewEmptyImpl, 0, cleanup_gEmptyDataRef);
+ gEmptyDataRef->ref();
+ return gEmptyDataRef;
}
// assumes fPtr was allocated via sk_malloc
« no previous file with comments | « include/core/SkPathRef.h ('k') | src/core/SkPathRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698