diff options
author | 2017-10-03 15:52:47 -0400 | |
---|---|---|
committer | 2017-10-04 21:38:33 +0000 | |
commit | a910c847e9d04e183e9e610902cbd363c8488196 (patch) | |
tree | 40218740b1bad94951010d8105bbecbd552fc76c /include/core | |
parent | e06739531b5067564c2ce90c35522c6590162e29 (diff) |
Clean up SkString reference counting a bit.
BUG=skia:7107
Change-Id: I47072bf31b902c79dbb850179ff6d35940de3e63
Reviewed-on: https://skia-review.googlesource.com/54720
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkString.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/include/core/SkString.h b/include/core/SkString.h index d9a922c0c3..04eb02afc0 100644 --- a/include/core/SkString.h +++ b/include/core/SkString.h @@ -12,6 +12,7 @@ #include "../private/SkTArray.h" #include "SkScalar.h" +#include "SkRefCnt.h" #include <atomic> #include <stdarg.h> @@ -240,16 +241,20 @@ public: private: struct Rec { public: + Rec() = delete; + static sk_sp<Rec> Make(const char text[], size_t len); uint32_t fLength; // logically size_t, but we want it to stay 32bits - std::atomic<int32_t> fRefCnt; + mutable std::atomic<int32_t> fRefCnt; char fBeginningOfData; char* data() { return &fBeginningOfData; } const char* data() const { return &fBeginningOfData; } - bool unique() { return fRefCnt.load(std::memory_order_acquire) == 1; } + void ref() const; + void unref() const; + bool unique() const; }; - Rec* fRec; + sk_sp<Rec> fRec; #ifdef SK_DEBUG void validate() const; @@ -258,8 +263,6 @@ private: #endif static const Rec gEmptyRec; - static Rec* AllocRec(const char text[], size_t len); - static Rec* RefRec(Rec*); }; /// Creates a new string and writes into it using a printf()-style format. |