diff options
author | 2016-12-01 14:05:38 -0500 | |
---|---|---|
committer | 2016-12-01 19:50:39 +0000 | |
commit | 0c32496e777732389125784457b7eb0a89789a2d (patch) | |
tree | 765c5a49a46079de3ae2e6cfb0439f9bb56ff8bf | |
parent | 5476128f0a88217414f05e6a7ee518cdb411d026 (diff) |
Avoid creating std::function in run_pipeline().
This avoids a malloc/free per SkRasterPipeline::run(), with no downside.
$ out/nanobench --benchType skcolorcodec --colorImages images/colorspace/201293.jpg --skps noskps --xform_only --srgb --ms 10000
target: 273µs
current: 395µs
this CL: 375µs
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD
Change-Id: Icd62f505f555ebf4ca66ee77a476f59cab68433d
Reviewed-on: https://skia-review.googlesource.com/5447
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Matt Sarett <msarett@google.com>
-rw-r--r-- | src/opts/SkRasterPipeline_opts.h | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/opts/SkRasterPipeline_opts.h b/src/opts/SkRasterPipeline_opts.h index 66668bd6d9..efeca8b46c 100644 --- a/src/opts/SkRasterPipeline_opts.h +++ b/src/opts/SkRasterPipeline_opts.h @@ -866,52 +866,54 @@ SI Fn enum_to_Fn(SkRasterPipeline::StockStage st) { return just_return; } -namespace SK_OPTS_NS { - - SI std::function<void(size_t, size_t, size_t)> - compile_pipeline(const SkRasterPipeline::Stage* stages, int nstages) { - struct Compiled { - Compiled(const SkRasterPipeline::Stage* stages, int nstages) { - if (nstages == 0) { - return; - } - fStart = enum_to_Fn(stages[0].stage); - for (int i = 0; i < nstages-1; i++) { - fStages[i].next = enum_to_Fn(stages[i+1].stage); - fStages[i].ctx = stages[i].ctx; - } - fStages[nstages-1].next = just_return; - fStages[nstages-1].ctx = stages[nstages-1].ctx; +namespace { + struct Compiled { + Compiled(const SkRasterPipeline::Stage* stages, int nstages) { + if (nstages == 0) { + return; + } + fStart = enum_to_Fn(stages[0].stage); + for (int i = 0; i < nstages-1; i++) { + fStages[i].next = enum_to_Fn(stages[i+1].stage); + fStages[i].ctx = stages[i].ctx; } + fStages[nstages-1].next = just_return; + fStages[nstages-1].ctx = stages[nstages-1].ctx; + } - void operator()(size_t x, size_t y, size_t n) { - float dx[] = { 0,1,2,3,4,5,6,7 }; - SkNf X = SkNf(x) + SkNf::Load(dx) + 0.5f, - Y = SkNf(y) + 0.5f, - _0 = SkNf(0), - _1 = SkNf(1); - - while (n >= N) { - fStart(fStages, x*N, X,Y,_1,_0, _0,_0,_0,_0); - X += (float)N; - x += N; - n -= N; - } - if (n) { - fStart(fStages, x*N+n, X,Y,_1,_0, _0,_0,_0,_0); - } + void operator()(size_t x, size_t y, size_t n) { + float dx[] = { 0,1,2,3,4,5,6,7 }; + SkNf X = SkNf(x) + SkNf::Load(dx) + 0.5f, + Y = SkNf(y) + 0.5f, + _0 = SkNf(0), + _1 = SkNf(1); + + while (n >= N) { + fStart(fStages, x*N, X,Y,_1,_0, _0,_0,_0,_0); + X += (float)N; + x += N; + n -= N; + } + if (n) { + fStart(fStages, x*N+n, X,Y,_1,_0, _0,_0,_0,_0); } + } - Fn fStart = just_return; - Stage fStages[SkRasterPipeline::kMaxStages]; + Fn fStart = just_return; + Stage fStages[SkRasterPipeline::kMaxStages]; + }; +} - } fn { stages, nstages }; - return fn; +namespace SK_OPTS_NS { + + SI std::function<void(size_t, size_t, size_t)> + compile_pipeline(const SkRasterPipeline::Stage* stages, int nstages) { + return Compiled{stages,nstages}; } SI void run_pipeline(size_t x, size_t y, size_t n, const SkRasterPipeline::Stage* stages, int nstages) { - compile_pipeline(stages, nstages)(x,y,n); + Compiled{stages,nstages}(x,y,n); } } // namespace SK_OPTS_NS |