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: [Patch] Fix num_get::do_get(bool&) vs 22.2.2.1.2, p16


... the version below is far better performance-wise: the loop is
much more tight, minimal I would say.

Again, tested x86linux, will commit tomorrow.

Paolo.

/////////////

2003-12-15  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (num_get::do_get(bool&)):
	Fail as soon as the begins of both truename and falsename
	stop to match; always leave __beg one position beyond the
	last char successfully matched.
	* testsuite/22_locale/num_get/get/char/8.cc: New.
	* testsuite/22_locale/num_get/get/wchar_t/8.cc: Likewise.
	
diff -prN libstdc++-v3-1/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-1/include/bits/locale_facets.tcc	Wed Dec 10 11:06:19 2003
--- libstdc++-v3/include/bits/locale_facets.tcc	Sun Dec 14 22:02:11 2003
*************** namespace std
*** 473,510 ****
  	  __use_cache<__cache_type> __uc;
  	  const locale& __loc = __io._M_getloc();
  	  const __cache_type* __lc = __uc(__loc);
!           const size_t __tn = __traits_type::length(__lc->_M_truename) - 1;
!           const size_t __fn = __traits_type::length(__lc->_M_falsename) - 1;
  
! 	  bool __testf = false;
! 	  bool __testt = false;
!           for (size_t __n = 0; __beg != __end; ++__n)
              {
!               const char_type __c = *__beg;
! 	      ++__beg;
! 
! 	      if (__n <= __fn)
! 		__testf = __traits_type::eq(__c, __lc->_M_falsename[__n]);
  
! 	      if (__n <= __tn)
! 		__testt = __traits_type::eq(__c, __lc->_M_truename[__n]);
  
!               if (!(__testf || __testt))
!                 {
!                   __err |= ios_base::failbit;
!                   break;
!                 }
!               else if (__testf && __n == __fn)
!                 {
!                   __v = 0;
!                   break;
!                 }
!               else if (__testt && __n == __tn)
!                 {
!                   __v = 1;
!                   break;
!                 }
              }
            if (__beg == __end)
              __err |= ios_base::eofbit;
          }
--- 473,508 ----
  	  __use_cache<__cache_type> __uc;
  	  const locale& __loc = __io._M_getloc();
  	  const __cache_type* __lc = __uc(__loc);
! 	  const size_t __tn = __traits_type::length(__lc->_M_truename);
! 	  const size_t __fn = __traits_type::length(__lc->_M_falsename);
  
! 	  bool __testf = true;
! 	  bool __testt = true;
! 	  size_t __n;
!           for (__n = 0; __beg != __end; ++__n, ++__beg)
              {
! 	      if (__testf)
! 		if (__n < __fn)
! 		  __testf = __traits_type::eq(*__beg, __lc->_M_falsename[__n]);
! 		else
! 		  break;
  
! 	      if (__testt)
! 		if (__n < __tn)
! 		  __testt = __traits_type::eq(*__beg, __lc->_M_truename[__n]);
! 		else
! 		  break;
  
! 	      if (!__testf && !__testt)
! 		break;      
              }
+ 	  if (__testf && __n == __fn)
+ 	    __v = 0;
+ 	  else if (__testt && __n == __tn)
+ 	    __v = 1;
+ 	  else
+ 	    __err |= ios_base::failbit;
+ 
            if (__beg == __end)
              __err |= ios_base::eofbit;
          }
diff -prN libstdc++-v3-1/testsuite/22_locale/num_get/get/char/8.cc libstdc++-v3/testsuite/22_locale/num_get/get/char/8.cc
*** libstdc++-v3-1/testsuite/22_locale/num_get/get/char/8.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/char/8.cc	Sun Dec 14 22:03:04 2003
***************
*** 0 ****
--- 1,70 ----
+ // 2003-12-15  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2003 Free Software Foundation
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 22.2.2.1.1  num_get members
+ 
+ #include <locale>
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ void test01()
+ {
+   using namespace std;
+   typedef istreambuf_iterator<char> iterator_type;
+ 
+   bool test __attribute__((unused)) = true;
+ 
+   bool b;
+ 
+   // cache the num_get facet
+   istringstream iss;
+   const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc()); 
+   const ios_base::iostate goodbit = ios_base::goodbit;
+   const ios_base::iostate failbit = ios_base::failbit;
+   ios_base::iostate err;
+   iterator_type end;
+ 
+   iss.setf(ios_base::boolalpha);
+   iss.str("faLse");
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == 'L' );
+   VERIFY( err == failbit );
+ 
+   iss.str("falsr");
+   iss.clear();  
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == 'r' );
+   VERIFY( err == failbit );
+ 
+   iss.str("trus");
+   iss.clear();
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == 's' );
+   VERIFY( err == failbit );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-1/testsuite/22_locale/num_get/get/wchar_t/8.cc libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/8.cc
*** libstdc++-v3-1/testsuite/22_locale/num_get/get/wchar_t/8.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/8.cc	Sun Dec 14 22:03:16 2003
***************
*** 0 ****
--- 1,70 ----
+ // 2003-12-15  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2003 Free Software Foundation
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 22.2.2.1.1  num_get members
+ 
+ #include <locale>
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ void test01()
+ {
+   using namespace std;
+   typedef istreambuf_iterator<wchar_t> iterator_type;
+ 
+   bool test __attribute__((unused)) = true;
+ 
+   bool b;
+ 
+   // cache the num_get facet
+   wistringstream iss;
+   const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc()); 
+   const ios_base::iostate goodbit = ios_base::goodbit;
+   const ios_base::iostate failbit = ios_base::failbit;
+   ios_base::iostate err;
+   iterator_type end;
+ 
+   iss.setf(ios_base::boolalpha);
+   iss.str(L"faLse");
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == L'L' );
+   VERIFY( err == failbit );
+ 
+   iss.str(L"falsr");
+   iss.clear();  
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == L'r' );
+   VERIFY( err == failbit );
+ 
+   iss.str(L"trus");
+   iss.clear();
+   err = goodbit;
+   end = ng.get(iss.rdbuf(), 0, iss, err, b);
+   VERIFY( *end == L's' );
+   VERIFY( err == failbit );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }

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