[PATCH 3 of 3] dirs.c: pass C string, not Python string, to _finddir()
Ryan McElroy
rmcelroy at fb.com
Thu May 14 18:28:19 CDT 2015
# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1431119592 25200
# Fri May 08 14:13:12 2015 -0700
# Node ID eac7da88b9233091ecf85bea44ca3d355e8eaac5
# Parent 6ea5874db04c722bcd5ec8c5341eb242aa894296
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 --git a/mercurial/dirs.c b/mercurial/dirs.c
--- a/mercurial/dirs.c
+++ b/mercurial/dirs.c
@@ -28,12 +28,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);
-
while (pos != -1) {
- if (s[pos] == '/')
+ if (path[pos] == '/')
break;
pos -= 1;
}
@@ -48,7 +46,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
@@ -100,7 +98,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);
More information about the Mercurial-devel
mailing list