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

Side by Side Diff: src/core/SkTRefArray.h

Issue 18770007: Add a 'unique' method to SkRefCnt, document the usage, and add support. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Update comments. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkPathRef.h ('k') | src/core/SkTypefaceCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // 1 //
2 // SkTRefArray.h 2 // SkTRefArray.h
3 // core 3 // core
4 // 4 //
5 // Created by Mike Reed on 7/17/12. 5 // Created by Mike Reed on 7/17/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 // 7 //
8 8
9 #ifndef SkTRefArray_DEFINED 9 #ifndef SkTRefArray_DEFINED
10 #define SkTRefArray_DEFINED 10 #define SkTRefArray_DEFINED
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const T& at(int index) const { 67 const T& at(int index) const {
68 SkASSERT((unsigned)index < (unsigned)fCount); 68 SkASSERT((unsigned)index < (unsigned)fCount);
69 return this->begin()[index]; 69 return this->begin()[index];
70 } 70 }
71 const T& operator[](int index) const { return this->at(index); } 71 const T& operator[](int index) const { return this->at(index); }
72 72
73 // For the writable methods, we assert that we are the only owner if we 73 // For the writable methods, we assert that we are the only owner if we
74 // call these, since other owners are not informed if we change an element. 74 // call these, since other owners are not informed if we change an element.
75 75
76 T* writableBegin() { 76 T* writableBegin() {
77 SkASSERT(1 == this->getRefCnt()); 77 SkASSERT(this->unique());
78 return (T*)(this + 1); 78 return (T*)(this + 1);
79 } 79 }
80 T* writableEnd() { 80 T* writableEnd() {
81 return this->writableBegin() + fCount; 81 return this->writableBegin() + fCount;
82 } 82 }
83 T& writableAt(int index) { 83 T& writableAt(int index) {
84 SkASSERT((unsigned)index < (unsigned)fCount); 84 SkASSERT((unsigned)index < (unsigned)fCount);
85 return this->writableBegin()[index]; 85 return this->writableBegin()[index];
86 } 86 }
87 87
(...skipping 15 matching lines...) Expand all
103 private: 103 private:
104 int fCount; 104 int fCount;
105 105
106 // hide this 106 // hide this
107 virtual ~SkTRefArray() {} 107 virtual ~SkTRefArray() {}
108 108
109 typedef SkRefCnt INHERITED; 109 typedef SkRefCnt INHERITED;
110 }; 110 };
111 111
112 #endif 112 #endif
OLDNEW
« no previous file with comments | « src/core/SkPathRef.h ('k') | src/core/SkTypefaceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698