This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] libstdc++/28277 (__add_grouping)


Hi,

tested x86-linux, committed to mainline.

Paolo.

/////////////////
2006-10-09  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/28277 (partial: __add_grouping)
	* include/bits/locale_facets.tcc (__add_grouping<>(_CharT*, _CharT,
	const char*, size_t, const _CharT*, const _CharT*)): Rewrite in
	non-recursive form.
Index: include/bits/locale_facets.tcc
===================================================================
--- include/bits/locale_facets.tcc	(revision 117571)
+++ include/bits/locale_facets.tcc	(working copy)
@@ -2590,19 +2590,33 @@
 		   const char* __gbeg, size_t __gsize,
 		   const _CharT* __first, const _CharT* __last)
     {
-      if (__last - __first > *__gbeg
-	  && static_cast<signed char>(*__gbeg) > 0)
+      size_t __idx = 0;
+      size_t __ctr = 0;
+
+      while (__last - __first > __gbeg[__idx]
+	     && static_cast<signed char>(__gbeg[__idx]) > 0)
 	{
-	  const bool __bump = __gsize != 1;
-	  __s = std::__add_grouping(__s,  __sep, __gbeg + __bump,
-				    __gsize - __bump, __first,
-				    __last - *__gbeg);
-	  __first = __last - *__gbeg;
-	  *__s++ = __sep;
+	  __last -= __gbeg[__idx];
+	  __idx < __gsize - 1 ? ++__idx : ++__ctr;
 	}
-      do
+
+      while (__first != __last)
 	*__s++ = *__first++;
-      while (__first != __last);
+
+      while (__ctr--)
+	{
+	  *__s++ = __sep;	  
+	  for (char __i = __gbeg[__idx]; __i > 0; --__i)
+	    *__s++ = *__first++;
+	}
+
+      while (__idx--)
+	{
+	  *__s++ = __sep;	  
+	  for (char __i = __gbeg[__idx]; __i > 0; --__i)
+	    *__s++ = *__first++;
+	}
+
       return __s;
     }
 

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