
Hi Eloi, you're correct and I'll fix that. I can even make it const reference. Running the test shows no real difference but that might be only because no expensive channels are being used. I'll commit the changes asap. Lubomir, please review the changes if your time allows. Affected files are channel_algorithm.hpp and gil_concept.hpp. Thanks, Christian On Fri, Nov 27, 2009 at 10:06 AM, Eloi Du Bois <eloi.du.bois@gmail.com> wrote:
Hi all,
I am creating a bunch of function for channel merging, thus I was looking in channel_algorithm.hpp and I saw something that may slow down processes... I don't know if I'm right, but on line 362:
/// \ingroup ChannelConvertAlgorithm /// \brief Converting from one channel type to another. template <typename DstChannel, typename SrcChannel> // Model ChannelConcept (could be channel references) inline typename channel_traits<DstChannel>::value_type channel_convert(SrcChannel src) { return channel_converter<typename channel_traits<SrcChannel>::value_type, typename channel_traits<DstChannel>::value_type>()(src); }
There is no reference on parameter src. That not a very good idea because references aren't hold by templates function (even if inlined). This may invoke copy constructor and can slow down the processes a "lot"...
Here is an example that shows I'm right in theory:
// "Slow" on big objects template<typename P> inline void testPtr1(P a) { std::cout << "In called function inequality ptr of a: " << (int)&a << std::endl; }
// Better template<typename P> inline void testPtr2(P &a) { std::cout << "In called function equality ptr of a: " << (int)&a << std::endl; }
template<typename P> void test(const P & a) { std::cout << "Base ptr of a: " << (int)&a << std::endl; testPtr1(a); }
int main() { int a = 0; test(a); return 0; }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users