From 482b0bc073ea4730c53ef2763885eba184ad8c0b Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 13 Dec 2016 00:33:33 +0100 Subject: [PATCH] Store weights of Weighted_Minkowski_distance in an array if dimension is known. This gains 15% on the running time of a real application in 2D. --- .../include/CGAL/Weighted_Minkowski_distance.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h index 5ef3cb1837c..4874babb571 100644 --- a/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h +++ b/Spatial_searching/include/CGAL/Weighted_Minkowski_distance.h @@ -27,11 +27,24 @@ #include #include +#include #include #include #include namespace CGAL { + namespace internal { + template + struct Array_or_vector_selector { + typedef std::vector type; + static void resize(type&v, std::size_t d) { v.resize(d); } + }; + template + struct Array_or_vector_selector > { + typedef cpp11::array type; + static void resize(type&, std::size_t CGAL_assertion_code(d)) { CGAL_assertion(d==D); } + }; + } template class Weighted_Minkowski_distance { @@ -41,8 +54,9 @@ namespace CGAL { typedef typename SearchTraits::Point_d Point_d; typedef Point_d Query_item; typedef typename SearchTraits::FT FT; - typedef std::vector Weight_vector; typedef typename internal::Get_dimension_tag::Dimension Dimension; + typedef internal::Array_or_vector_selector Weight_vector_traits; + typedef typename Weight_vector_traits::type Weight_vector; private: @@ -76,7 +90,7 @@ namespace CGAL { : traits(traits_),power(pow) { CGAL_assertion(power >= FT(0)); - the_weights.resize(dim); + Weight_vector_traits::resize(the_weights, dim); for (int i = 0; i < dim; ++i){ the_weights[i] = *begin; ++begin;