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>
This commit is contained in:
Mike Klein 2016-12-01 14:05:38 -05:00 committed by Skia Commit-Bot
parent 5476128f0a
commit 0c32496e77

View File

@ -866,10 +866,7 @@ SI Fn enum_to_Fn(SkRasterPipeline::StockStage st) {
return just_return; return just_return;
} }
namespace SK_OPTS_NS { namespace {
SI std::function<void(size_t, size_t, size_t)>
compile_pipeline(const SkRasterPipeline::Stage* stages, int nstages) {
struct Compiled { struct Compiled {
Compiled(const SkRasterPipeline::Stage* stages, int nstages) { Compiled(const SkRasterPipeline::Stage* stages, int nstages) {
if (nstages == 0) { if (nstages == 0) {
@ -904,14 +901,19 @@ namespace SK_OPTS_NS {
Fn fStart = just_return; Fn fStart = just_return;
Stage fStages[SkRasterPipeline::kMaxStages]; Stage fStages[SkRasterPipeline::kMaxStages];
};
}
} fn { stages, nstages }; namespace SK_OPTS_NS {
return fn;
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, SI void run_pipeline(size_t x, size_t y, size_t n,
const SkRasterPipeline::Stage* stages, int nstages) { const SkRasterPipeline::Stage* stages, int nstages) {
compile_pipeline(stages, nstages)(x,y,n); Compiled{stages,nstages}(x,y,n);
} }
} // namespace SK_OPTS_NS } // namespace SK_OPTS_NS