[PATCH 2 of 2] dirs.c: pass C string, not Python string, to _finddir()

Martin von Zweigbergk martinvonz at google.com
Fri May 8 17:06:04 CDT 2015


Please ignore these two patches. I think I will go another route.

On Fri, May 8, 2015 at 2:32 PM Martin von Zweigbergk <martinvonz at google.com>
wrote:

> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz at google.com>
> # Date 1431119592 25200
> #      Fri May 08 14:13:12 2015 -0700
> # Node ID 4885053a1ec3e85d79778bd877b6a29046b18d48
> # Parent  e8751ee69e5fdcd26ff58af3510a390dee7bacf6
> dirs.c: pass C string, not Python string, to _finddir()
>
> The callers already have the C string, and although the
> PyString_AS_STRING() macro is probably free, this simplifies the code.
>
> diff -r e8751ee69e5f -r 4885053a1ec3 mercurial/dirs.c
> --- a/mercurial/dirs.c  Fri May 08 14:11:00 2015 -0700
> +++ b/mercurial/dirs.c  Fri May 08 14:13:12 2015 -0700
> @@ -29,12 +29,10 @@
>         PyObject *dict;
>  } dirsObject;
>
> -static inline Py_ssize_t _finddir(PyObject *path, Py_ssize_t pos)
> +static inline Py_ssize_t _finddir(const char *path, Py_ssize_t pos)
>  {
> -       const char *s = PyString_AS_STRING(path);
> -
> -       const char *ret = strchr(s + pos, '/');
> -       return (ret != NULL) ? (ret - s) : -1;
> +       const char *ret = strchr(path + pos, '/');
> +       return (ret != NULL) ? (ret - path) : -1;
>  }
>
>  static int _addpath(PyObject *dirs, PyObject *path)
> @@ -45,7 +43,7 @@
>         PyObject *key = NULL;
>         int ret = -1;
>
> -       while ((pos = _finddir(path, pos + 1)) != -1) {
> +       while ((pos = _finddir(cpath, pos + 1)) != -1) {
>                 PyObject *val;
>
>                 /* It's likely that every prefix already has an entry
> @@ -112,7 +110,7 @@
>         PyObject *key = NULL;
>         int ret = -1;
>
> -       while ((pos = _finddir(path, pos + 1)) != -1) {
> +       while ((pos = _finddir(cpath, pos + 1)) != -1) {
>                 PyObject *val;
>
>                 key = PyString_FromStringAndSize(cpath, pos);
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150508/53188ace/attachment.html>


More information about the Mercurial-devel mailing list