##// END OF EJS Templates
store: implement lowerencode in C
Bryan O'Sullivan -
r18430:0459c655 default
parent child Browse files
Show More
@@ -1508,6 +1508,7 b' static char parsers_doc[] = "Efficient c'
1508 1508
1509 1509 PyObject *encodedir(PyObject *self, PyObject *args);
1510 1510 PyObject *pathencode(PyObject *self, PyObject *args);
1511 PyObject *lowerencode(PyObject *self, PyObject *args);
1511 1512
1512 1513 static PyMethodDef methods[] = {
1513 1514 {"pack_dirstate", pack_dirstate, METH_VARARGS, "pack a dirstate\n"},
@@ -1516,6 +1517,7 b' static PyMethodDef methods[] = {'
1516 1517 {"parse_index2", parse_index2, METH_VARARGS, "parse a revlog index\n"},
1517 1518 {"encodedir", encodedir, METH_VARARGS, "encodedir a path\n"},
1518 1519 {"pathencode", pathencode, METH_VARARGS, "fncache-encode a path\n"},
1520 {"lowerencode", lowerencode, METH_VARARGS, "lower-encode a path\n"},
1519 1521 {NULL, NULL}
1520 1522 };
1521 1523
@@ -15,6 +15,7 b''
15 15 * required.
16 16 */
17 17
18 #define PY_SSIZE_T_CLEAN
18 19 #include <Python.h>
19 20 #include <assert.h>
20 21 #include <ctype.h>
@@ -481,6 +482,47 b' static Py_ssize_t basicencode(char *dest'
481 482
482 483 static const Py_ssize_t maxstorepathlen = 120;
483 484
485 static Py_ssize_t _lowerencode(char *dest, size_t destsize,
486 const char *src, Py_ssize_t len)
487 {
488 static const uint32_t onebyte[8] = {
489 1, 0x2bfffbfb, 0xe8000001, 0x2fffffff
490 };
491
492 static const uint32_t lower[8] = { 0, 0, 0x7fffffe };
493
494 Py_ssize_t i, destlen = 0;
495
496 for (i = 0; i < len; i++) {
497 if (inset(onebyte, src[i]))
498 charcopy(dest, &destlen, destsize, src[i]);
499 else if (inset(lower, src[i]))
500 charcopy(dest, &destlen, destsize, src[i] + 32);
501 else
502 escape3(dest, &destlen, destsize, src[i]);
503 }
504
505 return destlen;
506 }
507
508 PyObject *lowerencode(PyObject *self, PyObject *args)
509 {
510 char *path;
511 Py_ssize_t len, newlen;
512 PyObject *ret;
513
514 if (!PyArg_ParseTuple(args, "s#:lowerencode", &path, &len))
515 return NULL;
516
517 newlen = _lowerencode(NULL, 0, path, len);
518 ret = PyString_FromStringAndSize(NULL, newlen);
519 if (ret)
520 newlen = _lowerencode(PyString_AS_STRING(ret), newlen,
521 path, len);
522
523 return ret;
524 }
525
484 526 /*
485 527 * We currently implement only basic encoding.
486 528 *
@@ -132,7 +132,7 b' def _buildlowerencodefun():'
132 132 cmap[chr(x)] = chr(x).lower()
133 133 return lambda s: "".join([cmap[c] for c in s])
134 134
135 lowerencode = _buildlowerencodefun()
135 lowerencode = getattr(parsers, 'lowerencode', None) or _buildlowerencodefun()
136 136
137 137 # Windows reserved names: con, prn, aux, nul, com1..com9, lpt1..lpt9
138 138 _winres3 = ('aux', 'con', 'prn', 'nul') # length 3
General Comments 0
You need to be logged in to leave comments. Login now