Patchwork [v3] libstdc++/45488

login
register
mail settings
Submitter Paolo Carlini
Date Sept. 1, 2010, 11 p.m.
Message ID <4C7EDB26.30902@oracle.com>
Download mbox | patch
Permalink /patch/63423/
State New
Headers show

Comments

Paolo Carlini - Sept. 1, 2010, 11 p.m.
Hi,

tested x86_64-linux, committed to mainline.

Paolo.

//////////////////////
2010-09-01  Christopher Yeleighton  <giecrilj@stegny.2a.pl>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/45488
	* include/bits/stl_algobase.h (lower_bound): Clean-up a tad, move
	two variables inside the main loop.
	* include/bits/stl_algo.h (lower_bound, upper_bound, equal_range):
	Likewise.

Patch

Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h	(revision 163743)
+++ include/bits/stl_algobase.h	(working copy)
@@ -945,13 +945,11 @@ 
       __glibcxx_requires_partitioned_lower(__first, __last, __val);
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle;
 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (*__middle < __val)
 	    {
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h	(revision 163743)
+++ include/bits/stl_algo.h	(working copy)
@@ -2403,13 +2403,11 @@ 
 						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle;
 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (__comp(*__middle, __val))
 	    {
@@ -2450,13 +2448,11 @@ 
       __glibcxx_requires_partitioned_upper(__first, __last, __val);
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle;
 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (__val < *__middle)
 	    __len = __half;
@@ -2503,13 +2499,11 @@ 
 						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle;
 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (__comp(__val, *__middle))
 	    __len = __half;
@@ -2558,13 +2552,11 @@ 
       __glibcxx_requires_partitioned_upper(__first, __last, __val);      
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle, __left, __right;
-
+ 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (*__middle < __val)
 	    {
@@ -2576,9 +2568,11 @@ 
 	    __len = __half;
 	  else
 	    {
-	      __left = std::lower_bound(__first, __middle, __val);
+	      _ForwardIterator __left = std::lower_bound(__first, __middle,
+							 __val);
 	      std::advance(__first, __len);
-	      __right = std::upper_bound(++__middle, __first, __val);
+	      _ForwardIterator __right = std::upper_bound(++__middle, __first,
+							  __val);
 	      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
 	    }
 	}
@@ -2605,8 +2599,7 @@ 
   template<typename _ForwardIterator, typename _Tp, typename _Compare>
     pair<_ForwardIterator, _ForwardIterator>
     equal_range(_ForwardIterator __first, _ForwardIterator __last,
-		const _Tp& __val,
-		_Compare __comp)
+		const _Tp& __val, _Compare __comp)
     {
       typedef typename iterator_traits<_ForwardIterator>::value_type
 	_ValueType;
@@ -2625,13 +2618,11 @@ 
 						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
-      _DistanceType __half;
-      _ForwardIterator __middle, __left, __right;
 
       while (__len > 0)
 	{
-	  __half = __len >> 1;
-	  __middle = __first;
+	  _DistanceType __half = __len >> 1;
+	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __half);
 	  if (__comp(*__middle, __val))
 	    {
@@ -2643,9 +2634,11 @@ 
 	    __len = __half;
 	  else
 	    {
-	      __left = std::lower_bound(__first, __middle, __val, __comp);
+	      _ForwardIterator __left = std::lower_bound(__first, __middle,
+							 __val, __comp);
 	      std::advance(__first, __len);
-	      __right = std::upper_bound(++__middle, __first, __val, __comp);
+	      _ForwardIterator __right = std::upper_bound(++__middle, __first,
+							  __val, __comp);
 	      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
 	    }
 	}