From f98862c39b7e79a35f1907cb94240f5d0545fe7b Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 24 Nov 2014 14:45:47 -0800 Subject: SkRecord: outline methods that are not called O(N) times. Looks like a noop-to-minor-win: tabl_sahadan.skp 94.9us -> 98.6us 1x desk_jsfiddlebigcar.skp 38.9us -> 39.7us 1x desk_silkfinance.skp 78us -> 78.9us 1x desk_jsfiddlehumperclip.skp 43.8us -> 44.3us 1x desk_sfgate.skp 547us -> 548us 1x tabl_gmail.skp 19.9us -> 19.8us 1x tabl_worldjournal.skp 230us -> 229us 1x desk_css3gradients.skp 248us -> 247us 1x tabl_cnn.skp 205us -> 203us 0.99x desk_linkedin.skp 342us -> 340us 0.99x desk_wowwiki.skp 1.63ms -> 1.62ms 0.99x tabl_cnet.skp 142us -> 141us 0.99x desk_pokemonwiki.skp 9.76ms -> 9.67ms 0.99x desk_espn.skp 267us -> 264us 0.99x desk_youtube.skp 576us -> 570us 0.99x tabl_pravda.skp 238us -> 235us 0.99x tabl_ukwsj.skp 566us -> 560us 0.99x tabl_engadget.skp 630us -> 622us 0.99x desk_googlespreadsheetdashed.skp 1.66ms -> 1.64ms 0.99x desk_mobilenews.skp 486us -> 480us 0.99x tabl_googlecalendar.skp 211us -> 208us 0.99x desk_samoasvg.skp 740us -> 730us 0.99x desk_gws.skp 187us -> 184us 0.99x desk_ebay.skp 234us -> 230us 0.99x desk_mapsvg.skp 1.6ms -> 1.58ms 0.98x tabl_nytimes.skp 130us -> 128us 0.98x tabl_googleblog.skp 305us -> 300us 0.98x desk_fontwipe.skp 40.3us -> 39.6us 0.98x desk_tigersvg.skp 189us -> 186us 0.98x tabl_androidpolice.skp 662us -> 650us 0.98x desk_wordpress.skp 824us -> 809us 0.98x tabl_mlb.skp 338us -> 331us 0.98x tabl_culturalsolutions.skp 390us -> 382us 0.98x desk_baidu.skp 213us -> 208us 0.98x tabl_gspro.skp 72.9us -> 71.1us 0.97x tabl_nofolo.skp 74us -> 71.9us 0.97x desk_yahooanswers.skp 173us -> 168us 0.97x tabl_frantzen.skp 57.3us -> 55.6us 0.97x desk_chalkboard.skp 891us -> 865us 0.97x desk_pinterest.skp 154us -> 149us 0.97x desk_blogger.skp 537us -> 519us 0.97x tabl_hsfi.skp 10.1us -> 9.69us 0.96x desk_gmailthread.skp 333us -> 318us 0.96x tabl_digg.skp 926us -> 883us 0.95x desk_googlespreadsheet.skp 586us -> 558us 0.95x desk_forecastio.skp 101us -> 95.7us 0.95x desk_booking.skp 1.1ms -> 1.04ms 0.95x tabl_deviantart.skp 144us -> 136us 0.95x desk_facebook.skp 584us -> 553us 0.95x desk_weather.skp 289us -> 272us 0.94x desk_googlehome.skp 61.1us -> 57.5us 0.94x desk_googleplus.skp 914us -> 849us 0.93x desk_twitter.skp 499us -> 463us 0.93x BUG=skia: Review URL: https://codereview.chromium.org/756783002 --- gyp/core.gypi | 1 + src/core/SkRecord.cpp | 21 +++++++++++++++++++++ src/core/SkRecord.h | 20 ++++++-------------- 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 src/core/SkRecord.cpp diff --git a/gyp/core.gypi b/gyp/core.gypi index 01838a34bb..a4d5c2c60a 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -154,6 +154,7 @@ '<(skia_src_path)/core/SkReadBuffer.h', '<(skia_src_path)/core/SkReadBuffer.cpp', '<(skia_src_path)/core/SkReader32.h', + '<(skia_src_path)/core/SkRecord.cpp', '<(skia_src_path)/core/SkRecordDraw.cpp', '<(skia_src_path)/core/SkRecordOpts.cpp', '<(skia_src_path)/core/SkRecorder.cpp', diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp new file mode 100644 index 0000000000..e2d919b777 --- /dev/null +++ b/src/core/SkRecord.cpp @@ -0,0 +1,21 @@ +#include "SkRecord.h" + +SkRecord::~SkRecord() { + Destroyer destroyer; + for (unsigned i = 0; i < this->count(); i++) { + this->mutate(i, destroyer); + } +} + +void SkRecord::grow() { + SkASSERT(fCount == fReserved); + fReserved = SkTMax(kFirstReserveCount, fReserved*2); + fRecords.realloc(fReserved); + fTypes.realloc(fReserved); +} + +size_t SkRecord::bytesUsed() const { + return fAlloc.approxBytesAllocated() + + fReserved * (sizeof(Record) + sizeof(Type8)) + + sizeof(SkRecord); +} diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h index 8179b06376..a8b4256adf 100644 --- a/src/core/SkRecord.h +++ b/src/core/SkRecord.h @@ -31,13 +31,7 @@ class SkRecord : public SkNVRefCnt { }; public: SkRecord() : fCount(0), fReserved(0) {} - - ~SkRecord() { - Destroyer destroyer; - for (unsigned i = 0; i < this->count(); i++) { - this->mutate(i, destroyer); - } - } + ~SkRecord(); // Returns the number of canvas commands in this SkRecord. unsigned count() const { return fCount; } @@ -76,11 +70,8 @@ public: template T* append() { if (fCount == fReserved) { - fReserved = SkTMax(kFirstReserveCount, fReserved*2); - fRecords.realloc(fReserved); - fTypes.realloc(fReserved); + this->grow(); } - fTypes[fCount] = T::kType; return fRecords[fCount++].set(this->allocCommand()); } @@ -115,9 +106,7 @@ public: // Does not return the bytes in any pointers embedded in the Records; callers // need to iterate with a visitor to measure those they care for. - size_t bytesUsed() const { return fAlloc.approxBytesAllocated() + - fReserved * (sizeof(Record) + sizeof(Type8)) + - sizeof(SkRecord); } + size_t bytesUsed() const; private: // Implementation notes! @@ -184,6 +173,9 @@ private: template SK_WHEN(!SkTIsEmpty, T*) allocCommand() { return this->alloc(); } + // Called when we've run out of room to record new commands. + void grow(); + // An untyped pointer to some bytes in fAlloc. This is the interface for polymorphic dispatch: // visit() and mutate() work with the parallel fTypes array to do the work of a vtable. struct Record { -- cgit v1.2.3