diff --git a/Eigen/src/Core/Fill.h b/Eigen/src/Core/Fill.h index cacf921c2..ccbeb50f0 100644 --- a/Eigen/src/Core/Fill.h +++ b/Eigen/src/Core/Fill.h @@ -20,11 +20,14 @@ namespace internal { template struct eigen_fill_helper : std::false_type {}; +// Only enable std::fill_n for trivially copyable scalars. GCC's libstdc++ +// fill_n pessimizes non-trivially-copyable types (extra moves per iteration), +// causing measurable regressions for types like AutoDiffScalar (issue #2956). template -struct eigen_fill_helper> : std::true_type {}; +struct eigen_fill_helper> : std::is_trivially_copyable {}; template -struct eigen_fill_helper> : std::true_type {}; +struct eigen_fill_helper> : std::is_trivially_copyable {}; template struct eigen_fill_helper> : eigen_fill_helper {};