Patchwork [2,of,2] parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 9, 2015, 3:23 p.m.
Message ID <1c4b92bdaacf011f9007.1441812227@mimosa>
Download mbox | patch
Permalink /patch/10437/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 9, 2015, 3:23 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1441439435 -32400
#      Sat Sep 05 16:50:35 2015 +0900
# Node ID 1c4b92bdaacf011f9007a7d98302adb8c9cbe456
# Parent  cb61444f1cb87643e72f1323b03c03165d7352f8
parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers

With these 2 patches, fm1readmarkers() gets slightly faster:

  obsolete._fm1readmarkers() for 78644 entries
  58.0 -> 56.2msec
Augie Fackler - Sept. 9, 2015, 3:35 p.m.
On Thu, Sep 10, 2015 at 12:23:47AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1441439435 -32400
> #      Sat Sep 05 16:50:35 2015 +0900
> # Node ID 1c4b92bdaacf011f9007a7d98302adb8c9cbe456
> # Parent  cb61444f1cb87643e72f1323b03c03165d7352f8
> parsers: use PyTuple_New and SET_ITEM to construct metadata pair of markers

Queued, thanks. Nice little bit of trivia!

>
> With these 2 patches, fm1readmarkers() gets slightly faster:
>
>   obsolete._fm1readmarkers() for 78644 entries
>   58.0 -> 56.2msec
>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -2636,17 +2636,15 @@ static PyObject *fm1readmarker(const cha
>               metasize = (unsigned char)(*data++);
>               right = PyString_FromStringAndSize(meta, metasize);
>               meta += metasize;
> -		if (!left || !right) {
> +		tmp = PyTuple_New(2);
> +		if (!left || !right || !tmp) {
>                       Py_XDECREF(left);
>                       Py_XDECREF(right);
> +			Py_XDECREF(tmp);
>                       goto bail;
>               }
> -		tmp = PyTuple_Pack(2, left, right);
> -		Py_DECREF(left);
> -		Py_DECREF(right);
> -		if (!tmp) {
> -			goto bail;
> -		}
> +		PyTuple_SET_ITEM(tmp, 0, left);
> +		PyTuple_SET_ITEM(tmp, 1, right);
>               PyTuple_SET_ITEM(metadata, i, tmp);
>       }
>       ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags,
> _______________________________________________
> 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
@@ -2636,17 +2636,15 @@  static PyObject *fm1readmarker(const cha
 		metasize = (unsigned char)(*data++);
 		right = PyString_FromStringAndSize(meta, metasize);
 		meta += metasize;
-		if (!left || !right) {
+		tmp = PyTuple_New(2);
+		if (!left || !right || !tmp) {
 			Py_XDECREF(left);
 			Py_XDECREF(right);
+			Py_XDECREF(tmp);
 			goto bail;
 		}
-		tmp = PyTuple_Pack(2, left, right);
-		Py_DECREF(left);
-		Py_DECREF(right);
-		if (!tmp) {
-			goto bail;
-		}
+		PyTuple_SET_ITEM(tmp, 0, left);
+		PyTuple_SET_ITEM(tmp, 1, right);
 		PyTuple_SET_ITEM(metadata, i, tmp);
 	}
 	ret = Py_BuildValue("(OOHO(di)O)", prec, succs, flags,