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

Unified Diff: src/core/SkPictureFlat.h

Issue 134223002: fNextIndex is redundant. Remove it. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 11 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureFlat.h
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 57daa5e786b439ed00072c9d264e4e3c3896699c..13c65eed66e527358c6e004707e695df8798885f 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -392,7 +392,6 @@ public:
// TODO(mtklein): There's no reason to have the index start from 1. Clean this up.
// index 0 is always empty since it is used as a signal that find failed
fIndexedData.push(NULL);
- fNextIndex = 1;
}
~SkFlatDictionary() {
@@ -400,9 +399,8 @@ public:
}
int count() const {
- SkASSERT(fIndexedData.count() == fNextIndex);
- SkASSERT(fHash.count() == fNextIndex - 1);
- return fNextIndex - 1;
+ SkASSERT(fHash.count() == fIndexedData.count() - 1);
+ return fHash.count();
}
// For testing only. Index is zero-based.
@@ -450,11 +448,11 @@ public:
return flat;
}
- // findAndReturnMutableFlat gave us index (fNextIndex-1), but we'll use the old one.
- fIndexedData.remove(flat->index());
- fNextIndex--;
+ // findAndReturnMutableFlat put flat at the back. Swap it into found->index() instead.
+ SkASSERT(flat->index() == this->count());
flat->setIndex(found->index());
- fIndexedData[flat->index()] = flat;
+ fIndexedData.removeShuffle(found->index());
+ SkASSERT(flat == fIndexedData[found->index()]);
// findAndReturnMutableFlat already called fHash.add(), so we just clean up the old entry.
fHash.remove(*found);
@@ -538,15 +536,15 @@ private:
// As findAndReturnFlat, but returns a mutable pointer for internal use.
SkFlatData* findAndReturnMutableFlat(const T& element) {
// Only valid until the next call to resetScratch().
- const SkFlatData& scratch = this->resetScratch(element, fNextIndex);
+ const SkFlatData& scratch = this->resetScratch(element, this->count()+1);
SkFlatData* candidate = fHash.find(scratch);
if (candidate != NULL) return candidate;
SkFlatData* detached = this->detachScratch();
fHash.add(detached);
- *fIndexedData.insert(fNextIndex) = detached;
- fNextIndex++;
+ *fIndexedData.append() = detached;
+ SkASSERT(fIndexedData.top()->index() == this->count());
return detached;
}
@@ -607,9 +605,6 @@ private:
SkOrderedWriteBuffer fWriteBuffer;
bool fReady;
- // We map between SkFlatData and a 1-based integer index.
- int fNextIndex;
-
// For index -> SkFlatData. fIndexedData[0] is always NULL.
SkTDArray<const SkFlatData*> fIndexedData;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698