From: thiery Date: Sun, 23 Jan 2011 20:16:23 +0000 (+0000) Subject: Replace while+modulo by a bitwise operation X-Git-Tag: v3.6_beta2~454 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8d8521a35887b41cb63e3473c650140ea3322298 Replace while+modulo by a bitwise operation git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9475 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/msg/chord/chord.c b/examples/msg/chord/chord.c index 138a609ffd..08698f605d 100644 --- a/examples/msg/chord/chord.c +++ b/examples/msg/chord/chord.c @@ -131,14 +131,8 @@ static void chord_initialize(void) */ static int normalize(int id) { - // make sure id >= 0 - while (id < 0) { - id += nb_keys; - } - // make sure id < nb_keys - id = id % nb_keys; - - return id; + // like id % nb_keys, but works with negatives numbers (and faster) + return id & (nb_keys - 1); } /**