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

Unified Diff: src/pdf/SkPDFCanon.cpp

Issue 2253993002: SkPDF: cache metrics once. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2016-08-17 (Wednesday) 14:22:07 EDT Created 4 years, 4 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
Index: src/pdf/SkPDFCanon.cpp
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 3dcf4e9f0f743b66d07aab48061b6dffc6abf28e..dc40b076076b10e4d20b41bad911f2d1a90751e7 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -12,52 +12,25 @@
////////////////////////////////////////////////////////////////////////////////
-void SkPDFCanon::reset() {
- for (int i = 0; i < fFontRecords.count(); ++i) {
- fFontRecords[i].fFont->unref();
- }
- fFontRecords.reset();
-
- fFunctionShaderRecords.reset();
- fAlphaShaderRecords.reset();
- fImageShaderRecords.reset();
+namespace {
+template <typename K, typename V> struct KVUnrefer {
bungeman-skia 2016/08/17 19:03:07 This name makes me think it's going to unref both
hal.canary 2016/08/17 19:29:49 Done.
+ void operator()(K, V** v) { (*v)->unref(); }
+};
+}
+SkPDFCanon::~SkPDFCanon() {
// TODO(halcanary): make SkTHashSet work nicely with sk_sp<>,
// or use std::unordered_set<>
fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
- fGraphicStateRecords.reset();
-
- fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); });
- fPDFBitmapMap.reset();
+ fPDFBitmapMap.foreach(KVUnrefer<SkBitmapKey, SkPDFObject>());
+ fTypefaceMetrics.foreach(KVUnrefer<uint32_t, SkAdvancedTypefaceMetrics>());
+ fFontDescriptors.foreach(KVUnrefer<uint32_t, SkPDFDict>());
+ fFontMap.foreach(KVUnrefer<uint64_t, SkPDFFont>());
}
-////////////////////////////////////////////////////////////////////////////////
-
-SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
- uint16_t glyphID,
- SkPDFFont** relatedFontPtr) const {
- SkASSERT(relatedFontPtr);
-
- SkPDFFont* relatedFont = nullptr;
- for (int i = 0; i < fFontRecords.count(); ++i) {
- SkPDFFont::Match match = SkPDFFont::IsMatch(
- fFontRecords[i].fFont, fFontRecords[i].fFontID,
- fFontRecords[i].fGlyphID, fontID, glyphID);
- if (SkPDFFont::kExact_Match == match) {
- return fFontRecords[i].fFont;
- } else if (!relatedFont && SkPDFFont::kRelated_Match == match) {
- relatedFont = fFontRecords[i].fFont;
- }
- }
- *relatedFontPtr = relatedFont; // May still be nullptr.
- return nullptr;
-}
-
-void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) {
- SkPDFCanon::FontRec* rec = fFontRecords.push();
- rec->fFont = SkRef(font);
- rec->fFontID = fontID;
- rec->fGlyphID = fGlyphID;
+void SkPDFCanon::reset() {
+ this->~SkPDFCanon();
+ new (this)SkPDFCanon;
}
////////////////////////////////////////////////////////////////////////////////
« src/pdf/SkPDFCanon.h ('K') | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDocument.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698