public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Remove redundant comparison in debug mode
@ 2012-08-01 19:34 François Dumont
  2012-08-02 21:53 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: François Dumont @ 2012-08-01 19:34 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

Verifying number of comparisons invoked in different algos and different 
modes I remarked this small performance issue.

2012-08-01  François Dumont  <fdumont@gcc.gnu.org>

     * include/debug/functions.h (__check_partition_lower_aux): Remove
     redundant comparison with pivot value.
     (__check_partition_upper_aux): Likewise.

Tested under Linux x86_64 debug mode.

Ok for trunk ?

François

[-- Attachment #2: functions.h.patch --]
[-- Type: text/x-patch, Size: 5406 bytes --]

Index: include/debug/functions.h
===================================================================
--- include/debug/functions.h	(revision 189985)
+++ include/debug/functions.h	(working copy)
@@ -354,8 +354,12 @@
     {
       while (__first != __last && *__first < __value)
 	++__first;
-      while (__first != __last && !(*__first < __value))
-	++__first;
+      if (__first != __last)
+	{
+	  ++__first;
+	  while (__first != __last && !(*__first < __value))
+	    ++__first;
+	}
       return __first == __last;
     }
 
@@ -368,8 +372,10 @@
 			const _Safe_iterator<_Iterator, _Sequence>& __last,
 			const _Tp& __value,
 			std::random_access_iterator_tag __tag)
-    { return __check_partitioned_lower_aux(__first.base(), __last.base(),
-					   __value, __tag); }
+    {
+      return __check_partitioned_lower_aux(__first.base(), __last.base(),
+					   __value, __tag);
+    }
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // 270. Binary search requirements overly strict
@@ -378,8 +384,10 @@
     inline bool
     __check_partitioned_lower(_ForwardIterator __first,
 			      _ForwardIterator __last, const _Tp& __value)
-    { return __check_partitioned_lower_aux(__first, __last, __value,
-					   std::__iterator_category(__first)); }
+    {
+      return __check_partitioned_lower_aux(__first, __last, __value,
+					   std::__iterator_category(__first));
+    }
 
   template<typename _ForwardIterator, typename _Tp>
     inline bool
@@ -389,8 +397,12 @@
     {
       while (__first != __last && !(__value < *__first))
 	++__first;
-      while (__first != __last && __value < *__first)
-	++__first;
+      if (__first != __last)
+	{
+	  ++__first;
+	  while (__first != __last && __value < *__first)
+	    ++__first;
+	}
       return __first == __last;
     }
 
@@ -403,15 +415,19 @@
 			const _Safe_iterator<_Iterator, _Sequence>& __last,
 			const _Tp& __value,
 			std::random_access_iterator_tag __tag)
-    { return __check_partitioned_upper_aux(__first.base(), __last.base(),
-					   __value, __tag); }
+    {
+      return __check_partitioned_upper_aux(__first.base(), __last.base(),
+					   __value, __tag);
+    }
 
   template<typename _ForwardIterator, typename _Tp>
     inline bool
     __check_partitioned_upper(_ForwardIterator __first,
 			      _ForwardIterator __last, const _Tp& __value)
-    { return __check_partitioned_upper_aux(__first, __last, __value,
-					   std::__iterator_category(__first)); }
+    {
+      return __check_partitioned_upper_aux(__first, __last, __value,
+					   std::__iterator_category(__first));
+    }
 
   template<typename _ForwardIterator, typename _Tp, typename _Pred>
     inline bool
@@ -422,8 +438,12 @@
     {
       while (__first != __last && bool(__pred(*__first, __value)))
 	++__first;
-      while (__first != __last && !bool(__pred(*__first, __value)))
-	++__first;
+      if (__first != __last)
+	{
+	  ++__first;
+	  while (__first != __last && !bool(__pred(*__first, __value)))
+	    ++__first;
+	}
       return __first == __last;
     }
 
@@ -437,8 +457,10 @@
 			const _Safe_iterator<_Iterator, _Sequence>& __last,
 			const _Tp& __value, _Pred __pred,
 			std::random_access_iterator_tag __tag)
-    { return __check_partitioned_lower_aux(__first.base(), __last.base(),
-					   __value, __pred, __tag); }
+    {
+      return __check_partitioned_lower_aux(__first.base(), __last.base(),
+					   __value, __pred, __tag);
+    }
 
   // Determine if a sequence is partitioned w.r.t. this element.
   template<typename _ForwardIterator, typename _Tp, typename _Pred>
@@ -446,8 +468,10 @@
     __check_partitioned_lower(_ForwardIterator __first,
 			      _ForwardIterator __last, const _Tp& __value,
 			      _Pred __pred)
-    { return __check_partitioned_lower_aux(__first, __last, __value, __pred,
-					   std::__iterator_category(__first)); }
+    {
+      return __check_partitioned_lower_aux(__first, __last, __value, __pred,
+					   std::__iterator_category(__first));
+    }
 
   template<typename _ForwardIterator, typename _Tp, typename _Pred>
     inline bool
@@ -458,8 +482,12 @@
     {
       while (__first != __last && !bool(__pred(__value, *__first)))
 	++__first;
-      while (__first != __last && bool(__pred(__value, *__first)))
-	++__first;
+      if (__first != __last)
+	{
+	  ++__first;
+	  while (__first != __last && bool(__pred(__value, *__first)))
+	    ++__first;
+	}
       return __first == __last;
     }
 
@@ -473,16 +501,20 @@
 			const _Safe_iterator<_Iterator, _Sequence>& __last,
 			const _Tp& __value, _Pred __pred,
 			std::random_access_iterator_tag __tag)
-    { return __check_partitioned_upper_aux(__first.base(), __last.base(),
-					   __value, __pred, __tag); }
+    {
+      return __check_partitioned_upper_aux(__first.base(), __last.base(),
+					   __value, __pred, __tag);
+    }
 
   template<typename _ForwardIterator, typename _Tp, typename _Pred>
     inline bool
     __check_partitioned_upper(_ForwardIterator __first,
 			      _ForwardIterator __last, const _Tp& __value,
 			      _Pred __pred)
-    { return __check_partitioned_upper_aux(__first, __last, __value, __pred,
-					   std::__iterator_category(__first)); }
+    {
+      return __check_partitioned_upper_aux(__first, __last, __value, __pred,
+					   std::__iterator_category(__first));
+    }
 
   // Helper struct to detect random access safe iterators.
   template<typename _Iterator>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Remove redundant comparison in debug mode
  2012-08-01 19:34 Remove redundant comparison in debug mode François Dumont
@ 2012-08-02 21:53 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2012-08-02 21:53 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 1 August 2012 20:34, François Dumont wrote:
>
> Ok for trunk ?

OK, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-02 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-01 19:34 Remove redundant comparison in debug mode François Dumont
2012-08-02 21:53 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).