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

Unified Diff: src/core/SkData.cpp

Issue 306943003: SkLazyPtr, mk. 2 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: drop static Created 6 years, 7 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/SkXfermode.h ('k') | src/core/SkGraphics.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 2f079140677759b85a746d8c66e0a726a53b6368..c65328720a789051e49be9d41d4a0a6866a022fc 100644
--- a/src/core/SkData.cpp
+++ b/src/core/SkData.cpp
@@ -6,10 +6,10 @@
*/
#include "SkData.h"
+#include "SkLazyPtr.h"
+#include "SkOSFile.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
-#include "SkOSFile.h"
-#include "SkOnce.h"
SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) {
fPtr = ptr;
@@ -49,18 +49,14 @@ size_t SkData::copyRange(size_t offset, size_t length, void* buffer) const {
///////////////////////////////////////////////////////////////////////////////
-static SkData* gEmptyDataRef = NULL;
-static void cleanup_gEmptyDataRef() { gEmptyDataRef->unref(); }
-
-void SkData::NewEmptyImpl(int) {
- gEmptyDataRef = new SkData(NULL, 0, NULL, NULL);
+SkData* SkData::NewEmptyImpl() {
+ return new SkData(NULL, 0, NULL, NULL);
}
+void SkData::DeleteEmpty(SkData* ptr) { SkDELETE(ptr); }
SkData* SkData::NewEmpty() {
- SK_DECLARE_STATIC_ONCE(once);
- SkOnce(&once, SkData::NewEmptyImpl, 0, cleanup_gEmptyDataRef);
- gEmptyDataRef->ref();
- return gEmptyDataRef;
+ SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, NewEmptyImpl, DeleteEmpty);
+ return SkRef(empty.get());
}
// assumes fPtr was allocated via sk_malloc
« no previous file with comments | « include/core/SkXfermode.h ('k') | src/core/SkGraphics.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698