MCPcopy Create free account
hub / github.com/FastLED/FastLED / write

Method write

src/fl/gfx/raster_sparse.h:166–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164 static const int kMaxCacheSize = 8; // Max size for tiny cache.
165
166 void write(const vec2<u16> &pt, u8 value) {
167 // FL_WARN("write: " << pt.x << "," << pt.y << " value: " <<
168 // value); mSparseGrid.insert(pt, value);
169
170 u8 **cached = mCache.find_value(pt);
171 if (cached) {
172 u8 *val = *cached;
173 if (*val < value) {
174 *val = value;
175 }
176 return;
177 }
178 if (mCache.size() <= kMaxCacheSize) {
179 // cache it.
180 u8 *v = mSparseGrid.find_value(pt);
181 if (v == nullptr) {
182 // FL_WARN("write: " << pt.x << "," << pt.y << " value: "
183 // << value);
184 if (mSparseGrid.needs_rehash()) {
185 // mSparseGrid is about to rehash, so we need to clear the
186 // small cache because it shares pointers.
187 mCache.clear();
188 }
189
190 mSparseGrid.insert(pt, value);
191 return;
192 }
193 mCache.insert(pt, v);
194 if (*v < value) {
195 *v = value;
196 }
197 return;
198 } else {
199 // overflow, clear cache and write directly.
200 mCache.clear();
201 mSparseGrid.insert(pt, value);
202 return;
203 }
204 }
205
206 private:
207 using Key = vec2<u16>;

Callers

nothing calls this directly

Calls 4

find_valueMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected