[PATCH 2 of 2] reachableroots: unroll loop that checks if one of parents is reachable

Yuya Nishihara yuya at tcha.org
Sat Aug 22 07:53:47 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1439685037 -32400
#      Sun Aug 16 09:30:37 2015 +0900
# Node ID 7737721288cbade4ab725ac87d8a57d2a99fa649
# Parent  32fd293a3f4709841d1e555b9fe3040c086281a3
reachableroots: unroll loop that checks if one of parents is reachable

The difference is small, but fewer loops should be better in general:

  revset #0: 0::tip
  0) 0.001609
  1) 0.001510  93%

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1240,18 +1240,17 @@ static PyObject *reachableroots2(indexOb
 			 * index_get_parents */
 			if (r < 0)
 				goto bail;
-			for (k = 0; k < 2; k++) {
-				if ((revstates[parents[k] + 1] & RS_REACHABLE)
-				    && !(revstates[i + 1] & RS_REACHABLE)) {
-					revstates[i + 1] |= RS_REACHABLE;
-					val = PyInt_FromLong(i);
-					if (val == NULL)
-						goto bail;
-					r = PyList_Append(reachable, val);
-					Py_DECREF(val);
-					if (r < 0)
-						goto bail;
-				}
+			if (((revstates[parents[0] + 1] |
+			      revstates[parents[1] + 1]) & RS_REACHABLE)
+			    && !(revstates[i + 1] & RS_REACHABLE)) {
+				revstates[i + 1] |= RS_REACHABLE;
+				val = PyInt_FromLong(i);
+				if (val == NULL)
+					goto bail;
+				r = PyList_Append(reachable, val);
+				Py_DECREF(val);
+				if (r < 0)
+					goto bail;
 			}
 		}
 	}


More information about the Mercurial-devel mailing list