From fecfaf4092fec486aa7c6ea2f4e3121500180afe Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Sun, 27 Jul 2014 13:31:46 +0400 Subject: [PATCH] Using std::map in PlanCache --- modules/core/src/dxt.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index b57e4e8cc0..69cac1a0fc 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -43,6 +43,7 @@ #include "opencv2/core/opencl/runtime/opencl_clamdfft.hpp" #include "opencv2/core/opencl/runtime/opencl_core.hpp" #include "opencl_kernels.hpp" +#include namespace cv { @@ -1801,10 +1802,9 @@ private: String buildOptions; int thread_count; bool status; - -public: int dft_size; +public: OCL_FftPlan(int _size): dft_size(_size), status(true) { int min_radix; @@ -1999,18 +1999,17 @@ public: Ptr getFftPlan(int dft_size) { - for (size_t i = 0, size = planStorage.size(); i < size; ++i) + std::map >::iterator f = planStorage.find(dft_size); + if (f != planStorage.end()) { - Ptr plan = planStorage[i]; - if (plan->dft_size == dft_size) - { - return plan; - } + return f->second; + } + else + { + Ptr newPlan = Ptr(new OCL_FftPlan(dft_size)); + planStorage[dft_size] = newPlan; + return newPlan; } - - Ptr newPlan = Ptr(new OCL_FftPlan(dft_size)); - planStorage.push_back(newPlan); - return newPlan; } ~OCL_FftPlanCache() @@ -2023,8 +2022,7 @@ protected: planStorage() { } - - std::vector > planStorage; + std::map > planStorage; }; static bool ocl_dft_rows(InputArray _src, OutputArray _dst, int nonzero_rows, int flags, int fftType) -- GitLab