From 6e83423f1653b97915b80e3adab477e68d2b2933 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 10 Jan 2014 20:13:09 +0000 Subject: [PATCH] Eliminate useless NULL push by making fIndexedData 0-based. Depends on http://crrev.com/134223002 Testing: out/Debug/dm && out/Debug/tests && echo ok BUG=skia:1979 R=dominikg@chromium.org, tomhudson@chromium.org, halcanary@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/134283002 git-svn-id: http://skia.googlecode.com/svn/trunk@13028 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkPictureFlat.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 13c65ee..c3623ee 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -389,9 +389,6 @@ public: */ void reset() { fIndexedData.rewind(); - // 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); } ~SkFlatDictionary() { @@ -399,13 +396,13 @@ public: } int count() const { - SkASSERT(fHash.count() == fIndexedData.count() - 1); + SkASSERT(fHash.count() == fIndexedData.count()); return fHash.count(); } // For testing only. Index is zero-based. const SkFlatData* operator[](int index) { - return fIndexedData[index+1]; + return fIndexedData[index]; } /** @@ -449,10 +446,11 @@ public: } // findAndReturnMutableFlat put flat at the back. Swap it into found->index() instead. + // indices in SkFlatData are 1-based, while fIndexedData is 0-based. Watch out! SkASSERT(flat->index() == this->count()); flat->setIndex(found->index()); - fIndexedData.removeShuffle(found->index()); - SkASSERT(flat == fIndexedData[found->index()]); + fIndexedData.removeShuffle(found->index()-1); + SkASSERT(flat == fIndexedData[found->index()-1]); // findAndReturnMutableFlat already called fHash.add(), so we just clean up the old entry. fHash.remove(*found); @@ -474,7 +472,7 @@ public: } SkTRefArray* array = SkTRefArray::Create(count); for (int i = 0; i < count; i++) { - this->unflatten(&array->writableAt(i), fIndexedData[i+1]); + this->unflatten(&array->writableAt(i), fIndexedData[i]); } return array; } @@ -484,7 +482,8 @@ public: * Caller takes ownership of the result. */ T* unflatten(int index) const { - const SkFlatData* element = fIndexedData[index]; + // index is 1-based, while fIndexedData is 0-based. + const SkFlatData* element = fIndexedData[index-1]; SkASSERT(index == element->index()); T* dst = new T; @@ -605,7 +604,7 @@ private: SkOrderedWriteBuffer fWriteBuffer; bool fReady; - // For index -> SkFlatData. fIndexedData[0] is always NULL. + // For index -> SkFlatData. 0-based, while all indices in the API are 1-based. Careful! SkTDArray fIndexedData; // For SkFlatData -> cached SkFlatData, which has index(). -- 2.7.4