diff options
author | 2015-04-25 06:45:07 -0700 | |
---|---|---|
committer | 2015-04-25 06:45:07 -0700 | |
commit | 130444fdaf737c5931a934018ab50b0c91a3499e (patch) | |
tree | 9e853af14d9b8b3e38b344340379b74e1a27e475 /src/pdf/SkPDFDevice.cpp | |
parent | 8e71d38126df1ed40ee88107e681c8b62f726e30 (diff) |
SkPDF: Refactor SkPDFObject heiararchy.
Flatten and use a tagged union type
Δmemory ~= -2.4% ± 0.5%
Δtime ~= -1.2% ± 0.2%
BUG=skia:3585
Review URL: https://codereview.chromium.org/1069103003
Diffstat (limited to 'src/pdf/SkPDFDevice.cpp')
-rw-r--r-- | src/pdf/SkPDFDevice.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index b08bb174b1..40a4576cb6 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1299,15 +1299,14 @@ const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { SkPDFArray* SkPDFDevice::copyMediaBox() const { // should this be a singleton? - SkAutoTUnref<SkPDFInt> zero(SkNEW_ARGS(SkPDFInt, (0))); - SkPDFArray* mediaBox = SkNEW(SkPDFArray); + SkAutoTUnref<SkPDFArray> mediaBox(SkNEW(SkPDFArray)); mediaBox->reserve(4); - mediaBox->append(zero.get()); - mediaBox->append(zero.get()); + mediaBox->appendInt(0); + mediaBox->appendInt(0); mediaBox->appendInt(fPageSize.fWidth); mediaBox->appendInt(fPageSize.fHeight); - return mediaBox; + return mediaBox.detach(); } SkStreamAsset* SkPDFDevice::content() const { @@ -1505,7 +1504,7 @@ void SkPDFDevice::handleLinkToURL(SkData* urlData, const SkRect& r, urlData->size() - 1); SkAutoTUnref<SkPDFDict> action(SkNEW_ARGS(SkPDFDict, ("Action"))); action->insertName("S", "URI"); - action->insert("URI", SkNEW_ARGS(SkPDFString, (url)))->unref(); + action->insertString("URI", url); annotation->insert("A", action.get()); } @@ -1514,7 +1513,7 @@ void SkPDFDevice::handleLinkToNamedDest(SkData* nameData, const SkRect& r, SkAutoTUnref<SkPDFDict> annotation(createLinkAnnotation(r, matrix)); SkString name(static_cast<const char *>(nameData->data()), nameData->size() - 1); - annotation->insert("Dest", SkNEW_ARGS(SkPDFName, (name)))->unref(); + annotation->insertName("Dest", name); } struct NamedDestination { @@ -1522,9 +1521,7 @@ struct NamedDestination { SkPoint point; NamedDestination(const SkData* nameData, const SkPoint& point) - : nameData(nameData), point(point) { - nameData->ref(); - } + : nameData(SkRef(nameData)), point(point) {} ~NamedDestination() { nameData->unref(); @@ -1547,13 +1544,13 @@ void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const { NamedDestination* dest = fNamedDestinations[i]; SkAutoTUnref<SkPDFArray> pdfDest(SkNEW(SkPDFArray)); pdfDest->reserve(5); - pdfDest->append(SkNEW_ARGS(SkPDFObjRef, (page)))->unref(); + pdfDest->appendObjRef(SkRef(page)); pdfDest->appendName("XYZ"); pdfDest->appendScalar(dest->point.x()); pdfDest->appendScalar(dest->point.y()); pdfDest->appendInt(0); // Leave zoom unchanged - dict->insert(static_cast<const char *>(dest->nameData->data()), - pdfDest); + SkString name(static_cast<const char*>(dest->nameData->data())); + dict->insertObject(name, pdfDest.detach()); } } |