public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: One less subtraction in binary search iterations.
@ 2013-07-06 23:07 Wedson Almeida Filho
  2013-07-07  4:59 ` Joe Perches
  2013-07-08  1:46 ` Rusty Russell
  0 siblings, 2 replies; 10+ messages in thread
From: Wedson Almeida Filho @ 2013-07-06 23:07 UTC (permalink / raw)
  To: Rusty Russell, Tim Abbott; +Cc: linux-kernel, Wedson Almeida Filho

There is no functional change, but this change eliminates a subtraction that
the compiler doesn't optimize out (as of gcc 4.7.3).

Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
---
 lib/bsearch.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/bsearch.c b/lib/bsearch.c
index e33c179..3264146 100644
--- a/lib/bsearch.c
+++ b/lib/bsearch.c
@@ -37,7 +37,7 @@ void *bsearch(const void *key, const void *base, size_t num, size_t size,
 	int result;
 
 	while (start < end) {
-		size_t mid = start + (end - start) / 2;
+		size_t mid = (start + end) / 2;
 
 		result = cmp(key, base + mid * size);
 		if (result < 0)
-- 
1.7.9.5


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

end of thread, other threads:[~2013-07-15  5:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-06 23:07 [PATCH] lib: One less subtraction in binary search iterations Wedson Almeida Filho
2013-07-07  4:59 ` Joe Perches
2013-07-09  3:51   ` Wedson Almeida Filho
2013-07-09  4:12     ` Joe Perches
2013-07-09  4:58       ` Wedson Almeida Filho
2013-07-09  6:37         ` [PATCH v2] " Wedson Almeida Filho
2013-07-15  5:07           ` Rusty Russell
2013-07-09  7:47     ` [PATCH] " Vineet Gupta
2013-07-09  9:19       ` Mikael Pettersson
2013-07-08  1:46 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox