This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3] libstdc++/30127/34449


On 14/12/2007, Benjamin Kosnik <bkoz@redhat.com> wrote:
> Fixes for use_facet/has_facet: now facet hierarchy is checked, to make
> sure that use of derived-facet methods properly error when the locale
> only has the base facet.

Unless I'm missing something, these changes will affect performance
more than necessary.

In has_facet, the dynamic_cast to a pointer type cannot throw so is
the try-catch needed?

In use_facet, if the first dynamic_cast works, the second will too, so
there's no point doing it twice.

Something like this still pass the new tests.

Jon
Index: include/bits/locale_classes.h
===================================================================
--- include/bits/locale_classes.h	(revision 130956)
+++ include/bits/locale_classes.h	(working copy)
@@ -579,17 +579,8 @@
     {
       const size_t __i = _Facet::id._M_id();
       const locale::facet** __facets = __loc._M_impl->_M_facets;
-      bool __b(false);
-      try 
-	{
-	  if (__i < __loc._M_impl->_M_facets_size
-	      && dynamic_cast<const _Facet*>(__facets[__i]) != NULL)
-	    __b = true;
-	    
-	}
-      catch (...)
-	{ }
-      return __b;
+      return __i < __loc._M_impl->_M_facets_size
+	      && dynamic_cast<const _Facet*>(__facets[__i]) != NULL;
     }
 
   /**
@@ -611,8 +602,7 @@
     {
       const size_t __i = _Facet::id._M_id();
       const locale::facet** __facets = __loc._M_impl->_M_facets;
-      if (__i >= __loc._M_impl->_M_facets_size
-	  || dynamic_cast<const _Facet*>(__facets[__i]) == NULL)
+      if (__i >= __loc._M_impl->_M_facets_size || __facets[__i] == NULL)
         __throw_bad_cast();
       return dynamic_cast<const _Facet&>(*__facets[__i]);
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]