Chromium Code Reviews| Index: src/pdf/SkPDFTypes.cpp |
| diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp |
| index e6fe74447df989bedb1b9c6411ca786f83d263aa..ff80a255250190093152e8bd2cc53e1572765301 100644 |
| --- a/src/pdf/SkPDFTypes.cpp |
| +++ b/src/pdf/SkPDFTypes.cpp |
| @@ -263,21 +263,25 @@ void SkPDFAtom::addResources(SkPDFObjNumMap* map, |
| //////////////////////////////////////////////////////////////////////////////// |
| -SkPDFArray::SkPDFArray() {} |
| -SkPDFArray::~SkPDFArray() { |
| - for (SkPDFUnion& value : fValues) { |
| - value.~SkPDFUnion(); |
| - } |
| +SkPDFArray::SkPDFArray() { SkDEBUGCODE(fDumped = false;) } |
| + |
| +SkPDFArray::~SkPDFArray() { this->dump(); } |
| + |
| +void SkPDFArray::dump() { |
| fValues.reset(); |
| + SkDEBUGCODE(fDumped = true;) |
| } |
| int SkPDFArray::size() const { return fValues.count(); } |
| -void SkPDFArray::reserve(int length) { fValues.setReserve(length); } |
| +void SkPDFArray::reserve(int length) { |
| + // TODO: implement SkTArray<T>::reserve() |
|
tomhudson
2016/03/18 13:59:38
TODO! If you intend to leave undone, is there anyt
hal.canary
2016/03/18 21:18:07
I put more info in the TODO. I haven't had time t
|
| +} |
| void SkPDFArray::emitObject(SkWStream* stream, |
| const SkPDFObjNumMap& objNumMap, |
| const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| stream->writeText("["); |
| for (int i = 0; i < fValues.count(); i++) { |
| fValues[i].emitObject(stream, objNumMap, substitutes); |
| @@ -290,13 +294,14 @@ void SkPDFArray::emitObject(SkWStream* stream, |
| void SkPDFArray::addResources(SkPDFObjNumMap* catalog, |
| const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| for (const SkPDFUnion& value : fValues) { |
| value.addResources(catalog, substitutes); |
| } |
| } |
| void SkPDFArray::append(SkPDFUnion&& value) { |
| - new (fValues.append()) SkPDFUnion(std::move(value)); |
| + fValues.emplace_back(std::move(value)); |
| } |
| void SkPDFArray::appendInt(int32_t value) { |
| @@ -337,11 +342,19 @@ void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) { |
| /////////////////////////////////////////////////////////////////////////////// |
| -SkPDFDict::SkPDFDict() {} |
| +SkPDFDict::~SkPDFDict() { this->dump(); } |
| -SkPDFDict::~SkPDFDict() { this->clear(); } |
| +void SkPDFDict::dump() { |
| + fRecords.reset(); |
| + SkDEBUGCODE(fDumped = true;) |
| +} |
| -SkPDFDict::SkPDFDict(const char type[]) { this->insertName("Type", type); } |
| +SkPDFDict::SkPDFDict(const char type[]) { |
| + SkDEBUGCODE(fDumped = false;) |
| + if (type) { |
| + this->insertName("Type", type); |
| + } |
| +} |
| void SkPDFDict::emitObject(SkWStream* stream, |
| const SkPDFObjNumMap& objNumMap, |
| @@ -354,6 +367,7 @@ void SkPDFDict::emitObject(SkWStream* stream, |
| void SkPDFDict::emitAll(SkWStream* stream, |
| const SkPDFObjNumMap& objNumMap, |
| const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| for (int i = 0; i < fRecords.count(); i++) { |
| fRecords[i].fKey.emitObject(stream, objNumMap, substitutes); |
| stream->writeText(" "); |
| @@ -366,41 +380,48 @@ void SkPDFDict::emitAll(SkWStream* stream, |
| void SkPDFDict::addResources(SkPDFObjNumMap* catalog, |
| const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| for (int i = 0; i < fRecords.count(); i++) { |
| fRecords[i].fKey.addResources(catalog, substitutes); |
| fRecords[i].fValue.addResources(catalog, substitutes); |
| } |
| } |
| -void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) { |
| - Record* rec = fRecords.append(); |
| - SkASSERT(name.isName()); |
| - new (&rec->fKey) SkPDFUnion(std::move(name)); |
| - new (&rec->fValue) SkPDFUnion(std::move(value)); |
| +SkPDFDict::Record::Record(SkPDFUnion&& k, SkPDFUnion&& v) |
| + : fKey(std::move(k)), fValue(std::move(v)) {} |
| + |
| +SkPDFDict::Record::Record(SkPDFDict::Record&& o) |
| + : fKey(std::move(o.fKey)), fValue(std::move(o.fValue)) {} |
| + |
| +SkPDFDict::Record& SkPDFDict::Record::operator=(SkPDFDict::Record&& o) { |
|
tomhudson
2016/03/18 13:59:38
You want move assignment but no non-destructive no
hal.canary
2016/03/18 21:18:07
Yep. I have not needed those yet, so I don't defi
tomhudson
2016/03/21 13:54:30
Acknowledged.
|
| + fKey = std::move(o.fKey); |
| + fValue = std::move(o.fValue); |
| + return *this; |
| } |
| int SkPDFDict::size() const { return fRecords.count(); } |
| void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
| } |
| + |
| void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp))); |
| } |
| void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
| } |
| void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp))); |
| } |
| void SkPDFDict::insertBool(const char key[], bool value) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Bool(value)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Bool(value)); |
| } |
| void SkPDFDict::insertInt(const char key[], int32_t value) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Int(value)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Int(value)); |
| } |
| void SkPDFDict::insertInt(const char key[], size_t value) { |
| @@ -408,39 +429,46 @@ void SkPDFDict::insertInt(const char key[], size_t value) { |
| } |
| void SkPDFDict::insertScalar(const char key[], SkScalar value) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Scalar(value)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Scalar(value)); |
| } |
| void SkPDFDict::insertName(const char key[], const char name[]) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Name(name)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Name(name)); |
| } |
| void SkPDFDict::insertName(const char key[], const SkString& name) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::Name(name)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::Name(name)); |
| } |
| void SkPDFDict::insertString(const char key[], const char value[]) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::String(value)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::String(value)); |
| } |
| void SkPDFDict::insertString(const char key[], const SkString& value) { |
| - this->set(SkPDFUnion::Name(key), SkPDFUnion::String(value)); |
| + fRecords.emplace_back(SkPDFUnion::Name(key), SkPDFUnion::String(value)); |
| } |
| -void SkPDFDict::clear() { |
|
tomhudson
2016/03/18 13:59:38
What happened to clear()? Do we just not need to c
hal.canary
2016/03/18 21:18:07
clear() is superceded by drop(), which has the sam
tomhudson
2016/03/21 13:54:30
Acknowledged.
|
| - for (Record& rec : fRecords) { |
| - rec.fKey.~SkPDFUnion(); |
| - rec.fValue.~SkPDFUnion(); |
| - } |
| - fRecords.reset(); |
| +//////////////////////////////////////////////////////////////////////////////// |
| + |
| +SkPDFSharedStream::SkPDFSharedStream(SkStreamAsset* data) |
| + : fAsset(data), fDict(new SkPDFDict) { |
| + SkDEBUGCODE(fDumped = false;) |
| + SkASSERT(data); |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| +SkPDFSharedStream::~SkPDFSharedStream() { this->dump(); } |
| + |
| +void SkPDFSharedStream::dump() { |
| + fAsset.free(); |
| + fDict.reset(nullptr); |
| + SkDEBUGCODE(fDumped = true;) |
| +} |
| void SkPDFSharedStream::emitObject( |
| SkWStream* stream, |
| const SkPDFObjNumMap& objNumMap, |
| const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| SkDynamicMemoryWStream buffer; |
| SkDeflateWStream deflateWStream(&buffer); |
| // Since emitObject is const, this function doesn't change the dictionary. |
| @@ -467,6 +495,7 @@ void SkPDFSharedStream::emitObject( |
| void SkPDFSharedStream::addResources( |
| SkPDFObjNumMap* catalog, const SkPDFSubstituteMap& substitutes) const { |
| + SkASSERT(!fDumped); |
| fDict->addResources(catalog, substitutes); |
| } |
| @@ -496,7 +525,7 @@ bool SkPDFObjNumMap::addObject(SkPDFObject* obj) { |
| return false; |
| } |
| fObjectNumbers.set(obj, fObjectNumbers.count() + 1); |
| - fObjects.push(obj); |
| + fObjects.emplace_back(sk_ref_sp(obj)); |
|
tomhudson
2016/03/18 13:59:38
You're ref'ing an sp, but input is a raw pointer?
hal.canary
2016/03/18 21:18:07
yes. this is awkward now and I will fix it later.
tomhudson
2016/03/21 13:54:30
Plz to file bug or TODO about laters.
|
| return true; |
| } |