From fb9c3174c9771bd3dd658dd25205f1d1486778f7 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 27 May 2010 14:39:46 -0400 Subject: [PATCH] revert: re PR libstdc++/42832 (Revisit std::function for aliasing issues and efficiency) Revert: PR libstdc++/42832 * include/std/functional (function<>::swap): Perform bytewise swap of _M_functor. * include/tr1/functional (function<>::swap): Likewise. From-SVN: r159940 --- libstdc++-v3/ChangeLog | 8 ++++++++ libstdc++-v3/include/std/functional | 13 +++---------- libstdc++-v3/include/tr1/functional | 13 +++---------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0af8ae6c730..b6a0b1e9707 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2010-05-27 Jason Merrill + + Revert: + PR libstdc++/42832 + * include/std/functional (function<>::swap): Perform bytewise + swap of _M_functor. + * include/tr1/functional (function<>::swap): Likewise. + 2010-05-27 Paolo Carlini PR libstdc++/40497 diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 7f6d8b6c4f6..b6cc6d5e072 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -1948,16 +1948,9 @@ namespace std */ void swap(function& __x) { - /* We cannot perform direct assignments of the _M_functor - parts as they are of type _Any_data and have a different - dynamic type. Doing so would violate type-based aliasing - rules and lead to spurious miscompilations. - Instead perform a bytewise exchange of the memory of - both POD objects. - ??? A wordwise exchange honoring alignment of _M_functor - would be more efficient. See PR42845. */ - for (unsigned i = 0; i < sizeof (_M_functor._M_pod_data); ++i) - std::swap (_M_functor._M_pod_data[i], __x._M_functor._M_pod_data[i]); + _Any_data __old_functor = _M_functor; + _M_functor = __x._M_functor; + __x._M_functor = __old_functor; _Manager_type __old_manager = _M_manager; _M_manager = __x._M_manager; __x._M_manager = __old_manager; diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional index ae080bb5df9..3340de6fffc 100644 --- a/libstdc++-v3/include/tr1/functional +++ b/libstdc++-v3/include/tr1/functional @@ -1907,16 +1907,9 @@ namespace tr1 */ void swap(function& __x) { - /* We cannot perform direct assignments of the _M_functor - parts as they are of type _Any_data and have a different - dynamic type. Doing so would violate type-based aliasing - rules and lead to spurious miscompilations. - Instead perform a bytewise exchange of the memory of - both POD objects. - ??? A wordwise exchange honoring alignment of _M_functor - would be more efficient. See PR42845. */ - for (unsigned i = 0; i < sizeof (_M_functor._M_pod_data); ++i) - std::swap (_M_functor._M_pod_data[i], __x._M_functor._M_pod_data[i]); + _Any_data __old_functor = _M_functor; + _M_functor = __x._M_functor; + __x._M_functor = __old_functor; _Manager_type __old_manager = _M_manager; _M_manager = __x._M_manager; __x._M_manager = __old_manager;