[PATCH] fast osutil.c for win32
Adrian Buehlmann
adrian at cadifra.com
Fri Sep 5 14:45:01 UTC 2008
On 05.09.2008 15:52, Petr Kodl wrote:
> # HG changeset patch
> # User Petr Kodl <petrkodl at gmail.com>
> # Date 1220622704 14400
> # Node ID e7a4e81078f5cafafe089dea11b79e00171e1305
> # Parent 4e62be0208d3465cf241d8fb6fb7c9ce125a490b
> fast osutil.c for win32
[snip]
> +static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)
> +{
> + PyObject *pathobj = NULL,
> + *statobj = NULL,
> + *list = NULL,
> + *items = NULL,
> + *ctor_args = NULL,
> + *item0 = NULL,
> + *item1 = NULL,
> + *py_st = NULL;
> + HANDLE fh = 0;
> + struct non_posix_stat* stp=0;
> + static char *kwlist[] = { "path", "stat", NULL };
> + if(PyArg_ParseTupleAndKeywords(args,kwargs,"O|O:listdir",kwlist,&pathobj,&statobj))
Again, I suggest inserting spaces after comma, like the rest of osutil.c already does
> + {
> + int keepstat= statobj && PyObject_IsTrue(statobj);
maybe sticking to using tabs as indenting like most of osutil.c already does
would help to avoid such ugly misaligned indenting... ?
> + int unicode = allow_unicode() && PyUnicode_CheckExact(pathobj);
> + WIN32_FIND_DATAA fd_a;
> + WIN32_FIND_DATAW fd_w;
> + if(unicode)
> + {
> + Py_ssize_t len = PyUnicode_GET_SIZE(pathobj);
> + wchar_t *wpath = _alloca((len+5)*sizeof(wchar_t));
> + memset(wpath,0,(len+5)*sizeof(wchar_t));
> + if(PyUnicode_AsWideChar((PyUnicodeObject*)pathobj,wpath,len)!=len) return 0;
return on new line please, to be consistent with the preexisting style of osutil.c
> + if(len>0 && wpath[len-1]!=L':' && wpath[len-1]!=L'/' && wpath[len-1]!='\\') wpath[len++]=L'\\';
^ is this correct? (missing L?)
> + wcscpy(wpath+len,L"*.*");
> + fh = FindFirstFileW(wpath,&fd_w);
> + }
[snipped rest]
More information about the Mercurial-devel
mailing list