##// END OF EJS Templates
changelog: add class to represent parsed changelog revisions...
changelog: add class to represent parsed changelog revisions Currently, changelog entries are parsed into their respective components at read time. Many operations are only interested in a subset of fields of a changelog entry. The parsing and storing of all the fields adds avoidable overhead. This patch introduces the "changelogrevision" class. It takes changelog raw text and exposes the parsed results as attributes. The code for parsing changelog entries has been moved into its construction function. changelog.read() has been modified to use the new class internally while maintaining its existing API. Future patches will make revision parsing lazy. We implement the construction function of the new class with __new__ instead of __init__ so we can use a named tuple to represent the empty revision. This saves overhead and complexity of coercing later versions of this class to represent an empty instance. While we are here, we add a method on changelog to obtain an instance of the new type. The overhead of constructing the new class regresses performance of revsets accessing this data: author(mpm) 0.896565 0.929984 desc(bug) 0.887169 0.935642 105% date(2015) 0.878797 0.908094 extra(rebase_source) 0.865446 0.922624 106% author(mpm) or author(greg) 1.801832 1.902112 105% author(mpm) or desc(bug) 1.812438 1.860977 date(2015) or branch(default) 0.968276 1.005824 author(mpm) or desc(bug) or date(2015) or extra(rebase_source) 3.656193 3.743381 Once lazy parsing is implemented, these revsets will all be faster than before. There is no performance change on revsets that do not access this data. There /could/ be a performance regression on operations that perform several changelog reads. However, I can't think of anything outside of revsets and `hg log` (basically the same as a revset) that would be impacted.

File last commit:

r27060:4613a89b default
r28487:98d98a64 default
Show More
base85.c
182 lines | 3.4 KiB | text/x-c | CLexer
Brendan Cully
Add a base85 codec
r3283 /*
base85 codec
Copyright 2006 Brendan Cully <brendan@kublai.com>
This software may be used and distributed according to the terms of
the GNU General Public License, incorporated herein by reference.
Largely based on git's implementation
*/
Adrian Buehlmann
base85: use Py_ssize_t for string lengths
r16837 #define PY_SSIZE_T_CLEAN
Brendan Cully
Add a base85 codec
r3283 #include <Python.h>
Renato Cunha
base85.c: Added support for py3k....
r11362 #include "util.h"
Brendan Cully
Add a base85 codec
r3283 static const char b85chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~";
static char b85dec[256];
Augie Fackler
base85: clean up function definition style...
r27060 static void b85prep(void)
Brendan Cully
Add a base85 codec
r3283 {
Augie Fackler
base85: fix comparison of an int and a long...
r26074 unsigned i;
Brendan Cully
Add a base85 codec
r3283
memset(b85dec, 0, sizeof(b85dec));
for (i = 0; i < sizeof(b85chars); i++)
b85dec[(int)(b85chars[i])] = i + 1;
}
Augie Fackler
base85: clean up function definition style...
r27060 static PyObject *b85encode(PyObject *self, PyObject *args)
Brendan Cully
Add a base85 codec
r3283 {
const unsigned char *text;
PyObject *out;
char *dst;
Adrian Buehlmann
base85: use Py_ssize_t for string lengths
r16837 Py_ssize_t len, olen, i;
Brendan Cully
Add a base85 codec
r3283 unsigned int acc, val, ch;
Thomas Arendsen Hein
Some additional space/tab cleanups
r7190 int pad = 0;
Brendan Cully
Add a base85 codec
r3283
Alexis S. L. Carvalho
python2.5 PyArg_ParseTuple fix...
r3369 if (!PyArg_ParseTuple(args, "s#|i", &text, &len, &pad))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Thomas Arendsen Hein
Some additional space/tab cleanups
r7190 if (pad)
olen = ((len + 3) / 4 * 5) - 3;
else {
olen = len % 4;
if (olen)
olen++;
olen += len / 4 * 5;
}
Renato Cunha
base85.c: Added support for py3k....
r11362 if (!(out = PyBytes_FromStringAndSize(NULL, olen + 3)))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Renato Cunha
base85.c: Added support for py3k....
r11362 dst = PyBytes_AsString(out);
Brendan Cully
Add a base85 codec
r3283
Brendan Cully
Handle odd-sized base85 input and output
r3288 while (len) {
Brendan Cully
Add a base85 codec
r3283 acc = 0;
for (i = 24; i >= 0; i -= 8) {
ch = *text++;
acc |= ch << i;
if (--len == 0)
break;
}
for (i = 4; i >= 0; i--) {
val = acc % 85;
acc /= 85;
dst[i] = b85chars[val];
}
dst += 5;
}
Thomas Arendsen Hein
Some additional space/tab cleanups
r7190 if (!pad)
Renato Cunha
base85.c: Added support for py3k....
r11362 _PyBytes_Resize(&out, olen);
Brendan Cully
Handle odd-sized base85 input and output
r3288
Brendan Cully
Add a base85 codec
r3283 return out;
}
Augie Fackler
base85: clean up function definition style...
r27060 static PyObject *b85decode(PyObject *self, PyObject *args)
Brendan Cully
Add a base85 codec
r3283 {
PyObject *out;
const char *text;
char *dst;
Adrian Buehlmann
base85: use Py_ssize_t for string lengths
r16837 Py_ssize_t len, i, j, olen, cap;
int c;
Brendan Cully
Add a base85 codec
r3283 unsigned int acc;
Alexis S. L. Carvalho
python2.5 PyArg_ParseTuple fix...
r3369 if (!PyArg_ParseTuple(args, "s#", &text, &len))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Brendan Cully
Handle odd-sized base85 input and output
r3288 olen = len / 5 * 4;
i = len % 5;
if (i)
olen += i - 1;
Renato Cunha
base85.c: Added support for py3k....
r11362 if (!(out = PyBytes_FromStringAndSize(NULL, olen)))
Brendan Cully
Add a base85 codec
r3283 return NULL;
Renato Cunha
base85.c: Added support for py3k....
r11362 dst = PyBytes_AsString(out);
Brendan Cully
Add a base85 codec
r3283
Brendan Cully
Handle odd-sized base85 input and output
r3288 i = 0;
while (i < len)
Brendan Cully
Add a base85 codec
r3283 {
acc = 0;
Brendan Cully
Handle odd-sized base85 input and output
r3288 cap = len - i - 1;
if (cap > 4)
cap = 4;
for (j = 0; j < cap; i++, j++)
Brendan Cully
Add a base85 codec
r3283 {
c = b85dec[(int)*text++] - 1;
if (c < 0)
Matt Mackall
many, many trivial check-code fixups
r10282 return PyErr_Format(
PyExc_ValueError,
Adrian Buehlmann
base85: cast Py_ssize_t values to int (issue3481)...
r16848 "bad base85 character at position %d",
(int)i);
Brendan Cully
Add a base85 codec
r3283 acc = acc * 85 + c;
}
Brendan Cully
Handle odd-sized base85 input and output
r3288 if (i++ < len)
Brendan Cully
Add a base85 codec
r3283 {
c = b85dec[(int)*text++] - 1;
if (c < 0)
Matt Mackall
many, many trivial check-code fixups
r10282 return PyErr_Format(
PyExc_ValueError,
Adrian Buehlmann
base85: cast Py_ssize_t values to int (issue3481)...
r16848 "bad base85 character at position %d",
(int)i);
Brendan Cully
Handle odd-sized base85 input and output
r3288 /* overflow detection: 0xffffffff == "|NsC0",
* "|NsC" == 0x03030303 */
if (acc > 0x03030303 || (acc *= 85) > 0xffffffff - c)
Matt Mackall
many, many trivial check-code fixups
r10282 return PyErr_Format(
PyExc_ValueError,
Adrian Buehlmann
base85: cast Py_ssize_t values to int (issue3481)...
r16848 "bad base85 sequence at position %d",
(int)i);
Brendan Cully
Handle odd-sized base85 input and output
r3288 acc += c;
Brendan Cully
Add a base85 codec
r3283 }
Brendan Cully
Handle odd-sized base85 input and output
r3288 cap = olen < 4 ? olen : 4;
olen -= cap;
for (j = 0; j < 4 - cap; j++)
acc *= 85;
if (cap && cap < 4)
acc += 0xffffff >> (cap - 1) * 8;
for (j = 0; j < cap; j++)
Brendan Cully
Add a base85 codec
r3283 {
acc = (acc << 8) | (acc >> 24);
Brendan Cully
Handle odd-sized base85 input and output
r3288 *dst++ = acc;
Brendan Cully
Add a base85 codec
r3283 }
}
return out;
}
static char base85_doc[] = "Base85 Data Encoding";
static PyMethodDef methods[] = {
Brendan Cully
Handle odd-sized base85 input and output
r3288 {"b85encode", b85encode, METH_VARARGS,
Thomas Arendsen Hein
Some additional space/tab cleanups
r7190 "Encode text in base85.\n\n"
"If the second parameter is true, pad the result to a multiple of "
"five characters.\n"},
Brendan Cully
Handle odd-sized base85 input and output
r3288 {"b85decode", b85decode, METH_VARARGS, "Decode base85 text.\n"},
Brendan Cully
Add a base85 codec
r3283 {NULL, NULL}
};
Renato Cunha
base85.c: Added support for py3k....
r11362 #ifdef IS_PY3K
static struct PyModuleDef base85_module = {
PyModuleDef_HEAD_INIT,
"base85",
base85_doc,
-1,
methods
};
PyMODINIT_FUNC PyInit_base85(void)
{
b85prep();
return PyModule_Create(&base85_module);
}
#else
Brendan Cully
Add a base85 codec
r3283 PyMODINIT_FUNC initbase85(void)
{
Py_InitModule3("base85", methods, base85_doc);
b85prep();
}
Renato Cunha
base85.c: Added support for py3k....
r11362 #endif