Patchwork [4,of,7] reachableroots: extend "revstates" to array of bit flags

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 18, 2015, 2:42 p.m.
Message ID <2ca0b48b6de1c79bc205.1439908976@mimosa>
Download mbox | patch
Permalink /patch/10226/
State Accepted
Delegated to: Augie Fackler
Headers show

Comments

Yuya Nishihara - Aug. 18, 2015, 2:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1439533852 -32400
#      Fri Aug 14 15:30:52 2015 +0900
# Node ID 2ca0b48b6de1c79bc205e7a660a5531c125cad9e
# Parent  4aa3b50ba925959ff15a7f895710ccb900d095d3
reachableroots: extend "revstates" to array of bit flags
Augie Fackler - Aug. 18, 2015, 6:11 p.m.
On Tue, Aug 18, 2015 at 11:42:56PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1439533852 -32400
> #      Fri Aug 14 15:30:52 2015 +0900
> # Node ID 2ca0b48b6de1c79bc205e7a660a5531c125cad9e
> # Parent  4aa3b50ba925959ff15a7f895710ccb900d095d3
> reachableroots: extend "revstates" to array of bit flags

I've queued the first four, and once I hear about the questions I had
on patch 5 I'll enthusiastically take the rest of the series. That's
an awesome speedup.

>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -1130,9 +1130,10 @@ static PyObject *reachableroots(indexObj
>
>       /* Internal data structure:
>        * tovisit: array of length len+1 (all revs + nullrev), filled upto lentovisit
> -      * revstates: array of length len+1 (all revs + nullrev) 0: not seen, 1 seen*/
> +      * revstates: array of length len+1 (all revs + nullrev) */
>       int *tovisit = NULL;
>       long lentovisit = 0;
> +	enum { RS_SEEN = 1 };
>       char *revstates = NULL;
>
>       /* Get arguments */
> @@ -1173,9 +1174,9 @@ static PyObject *reachableroots(indexObj
>                       PyErr_SetString(PyExc_IndexError, "head out of range");
>                       goto bail;
>               }
> -		if (revstates[revnum+1] == 0) {
> +		if (!(revstates[revnum + 1] & RS_SEEN)) {
>                       tovisit[lentovisit++] = revnum;
> -			revstates[revnum+1]=1;
> +			revstates[revnum + 1] |= RS_SEEN;
>               }
>       }
>
> @@ -1203,10 +1204,10 @@ static PyObject *reachableroots(indexObj
>               if (r < 0)
>                       goto bail;
>               for (i = 0; i < 2; i++) {
> -			if (revstates[parents[i] + 1] == 0
> +			if (!(revstates[parents[i] + 1] & RS_SEEN)
>                           && parents[i] >= minroot) {
>                               tovisit[lentovisit++] = parents[i];
> -				revstates[parents[i] + 1] = 1;
> +				revstates[parents[i] + 1] |= RS_SEEN;
>                       }
>               }
>       }
> @@ -1218,7 +1219,7 @@ static PyObject *reachableroots(indexObj
>               if (minidx < 0)
>                       minidx = 0;
>               for (i = minidx; i < len; i++) {
> -			if (revstates[i + 1] != 1)
> +			if (!(revstates[i + 1] & RS_SEEN))
>                               continue;
>                       r = index_get_parents(self, i, parents, (int)len - 1);
>                       /* Corrupted index file, error is set from
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1130,9 +1130,10 @@  static PyObject *reachableroots(indexObj
 
 	/* Internal data structure:
 	 * tovisit: array of length len+1 (all revs + nullrev), filled upto lentovisit
-	 * revstates: array of length len+1 (all revs + nullrev) 0: not seen, 1 seen*/
+	 * revstates: array of length len+1 (all revs + nullrev) */
 	int *tovisit = NULL;
 	long lentovisit = 0;
+	enum { RS_SEEN = 1 };
 	char *revstates = NULL;
 
 	/* Get arguments */
@@ -1173,9 +1174,9 @@  static PyObject *reachableroots(indexObj
 			PyErr_SetString(PyExc_IndexError, "head out of range");
 			goto bail;
 		}
-		if (revstates[revnum+1] == 0) {
+		if (!(revstates[revnum + 1] & RS_SEEN)) {
 			tovisit[lentovisit++] = revnum;
-			revstates[revnum+1]=1;
+			revstates[revnum + 1] |= RS_SEEN;
 		}
 	}
 
@@ -1203,10 +1204,10 @@  static PyObject *reachableroots(indexObj
 		if (r < 0)
 			goto bail;
 		for (i = 0; i < 2; i++) {
-			if (revstates[parents[i] + 1] == 0
+			if (!(revstates[parents[i] + 1] & RS_SEEN)
 			    && parents[i] >= minroot) {
 				tovisit[lentovisit++] = parents[i];
-				revstates[parents[i] + 1] = 1;
+				revstates[parents[i] + 1] |= RS_SEEN;
 			}
 		}
 	}
@@ -1218,7 +1219,7 @@  static PyObject *reachableroots(indexObj
 		if (minidx < 0)
 			minidx = 0;
 		for (i = minidx; i < len; i++) {
-			if (revstates[i + 1] != 1)
+			if (!(revstates[i + 1] & RS_SEEN))
 				continue;
 			r = index_get_parents(self, i, parents, (int)len - 1);
 			/* Corrupted index file, error is set from