Mercurial > hg
changeset 7092:fb3fc27617a2
parsers: speed up hex decoding for manifests
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 12 Oct 2008 15:21:08 -0500 |
parents | 12b35ae03365 |
children | 16bafcebd3d1 |
files | mercurial/parsers.c |
diffstat | 1 files changed, 7 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/parsers.c Sun Oct 12 15:21:08 2008 -0500 +++ b/mercurial/parsers.c Sun Oct 12 15:21:08 2008 -0500 @@ -15,14 +15,13 @@ { if (c >= '0' && c <= '9') return c - '0'; - + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; if (c >= 'A' && c <= 'F') return c - 'A' + 10; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - - return -1; + PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); + return 0; } /* @@ -30,43 +29,21 @@ */ static PyObject *unhexlify(const char *str, int len) { - PyObject *ret = NULL; + PyObject *ret; const char *c; char *d; - if (len % 2) { - PyErr_SetString(PyExc_ValueError, - "input is not even in length"); - goto bail; - } - ret = PyString_FromStringAndSize(NULL, len / 2); if (!ret) - goto bail; + return NULL; - d = PyString_AsString(ret); - if (!d) - goto bail; - + d = PyString_AS_STRING(ret); for (c = str; c < str + len;) { int hi = hexdigit(*c++); int lo = hexdigit(*c++); - - if (hi == -1 || lo == -1) { - PyErr_SetString(PyExc_ValueError, - "input contains non-hex character"); - goto bail; - } - *d++ = (hi << 4) | lo; } - goto done; - -bail: - Py_XDECREF(ret); - ret = NULL; -done: return ret; }