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

Side by Side Diff: include/core/SkTDict.h

Issue 12315131: Make SkTDArray accessors const-friendly (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | « include/core/SkTDArray.h ('k') | src/core/SkPathHeap.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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkTDict_DEFINED 10 #ifndef SkTDict_DEFINED
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 { 77 {
78 if (value) 78 if (value)
79 *value = fArray[index].fValue; 79 *value = fArray[index].fValue;
80 return true; 80 return true;
81 } 81 }
82 return false; 82 return false;
83 } 83 }
84 84
85 bool findKey(T& value, const char** name) const 85 bool findKey(T& value, const char** name) const
86 { 86 {
87 Pair* end = fArray.end(); 87 const Pair* end = fArray.end();
88 for (Pair* pair = fArray.begin(); pair < end; pair++) { 88 for (const Pair* pair = fArray.begin(); pair < end; pair++) {
89 if (pair->fValue != value) 89 if (pair->fValue != value)
90 continue; 90 continue;
91 *name = pair->fName; 91 *name = pair->fName;
92 return true; 92 return true;
93 } 93 }
94 return false; 94 return false;
95 } 95 }
96 96
97 public: 97 public:
98 struct Pair { 98 struct Pair {
(...skipping 25 matching lines...) Expand all
124 if (fIter < fStop) 124 if (fIter < fStop)
125 { 125 {
126 name = fIter->fName; 126 name = fIter->fName;
127 if (value) 127 if (value)
128 *value = fIter->fValue; 128 *value = fIter->fValue;
129 fIter += 1; 129 fIter += 1;
130 } 130 }
131 return name; 131 return name;
132 } 132 }
133 private: 133 private:
134 Pair* fIter; 134 const Pair* fIter;
135 Pair* fStop; 135 const Pair* fStop;
136 }; 136 };
137 137
138 private: 138 private:
139 SkTDArray<Pair> fArray; 139 SkTDArray<Pair> fArray;
140 SkChunkAlloc fStrings; 140 SkChunkAlloc fStrings;
141 141
142 int find_index(const char name[]) const 142 int find_index(const char name[]) const
143 { 143 {
144 return find_index(name, strlen(name)); 144 return find_index(name, strlen(name));
145 } 145 }
146 146
147 int find_index(const char name[], size_t len) const 147 int find_index(const char name[], size_t len) const
148 { 148 {
149 SkASSERT(name); 149 SkASSERT(name);
150 150
151 int count = fArray.count(); 151 int count = fArray.count();
152 int index = ~0; 152 int index = ~0;
153 153
154 if (count) 154 if (count)
155 index = SkStrSearch(&fArray.begin()->fName, count, name, len, sizeof (Pair)); 155 index = SkStrSearch(&fArray.begin()->fName, count, name, len, sizeof (Pair));
156 return index; 156 return index;
157 } 157 }
158 friend class Iter; 158 friend class Iter;
159 }; 159 };
160 160
161 #endif 161 #endif
OLDNEW
« no previous file with comments | « include/core/SkTDArray.h ('k') | src/core/SkPathHeap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698