D4109: index: move more fields onto nodetree type
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Sun Aug 5 07:58:33 UTC 2018
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The fields moves are the ones that are not related to how the nodetree
is used in the index and that will make sense for the new nodetree
instance for a subset of the index that I'll add later.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D4109
AFFECTED FILES
mercurial/cext/revlog.c
CHANGE DETAILS
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -42,6 +42,10 @@
*/
typedef struct {
nodetreenode *nodes;
+ unsigned ntlength; /* # nodes in use */
+ unsigned ntcapacity; /* # nodes allocated */
+ int ntdepth; /* maximum depth of tree */
+ int ntsplits; /* # splits performed */
} nodetree;
/*
@@ -69,10 +73,6 @@
PyObject *headrevs; /* cache, invalidated on changes */
PyObject *filteredrevs;/* filtered revs set */
nodetree *nt; /* base-16 trie */
- unsigned ntlength; /* # nodes in use */
- unsigned ntcapacity; /* # nodes allocated */
- int ntdepth; /* maximum depth of tree */
- int ntsplits; /* # splits performed */
int ntrev; /* last rev scanned */
int ntlookups; /* # lookups */
int ntmisses; /* # lookups that miss the cache */
@@ -333,8 +333,6 @@
static PyObject *index_clearcaches(indexObject *self)
{
_index_clearcaches(self);
- self->ntlength = self->ntcapacity = 0;
- self->ntdepth = self->ntsplits = 0;
self->ntrev = -1;
self->ntlookups = self->ntmisses = 0;
Py_RETURN_NONE;
@@ -371,13 +369,15 @@
if (self->raw_length != self->length - 1)
istat(raw_length, "revs on disk");
istat(length, "revs in memory");
- istat(ntcapacity, "node trie capacity");
- istat(ntdepth, "node trie depth");
- istat(ntlength, "node trie count");
istat(ntlookups, "node trie lookups");
istat(ntmisses, "node trie misses");
istat(ntrev, "node trie last rev scanned");
- istat(ntsplits, "node trie splits");
+ if (self->nt) {
+ istat(nt->ntcapacity, "node trie capacity");
+ istat(nt->ntdepth, "node trie depth");
+ istat(nt->ntlength, "node trie count");
+ istat(nt->ntsplits, "node trie splits");
+ }
#undef istat
@@ -1018,23 +1018,24 @@
static int nt_new(indexObject *self)
{
- if (self->ntlength == self->ntcapacity) {
- if (self->ntcapacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
+ nodetree *nt = self->nt;
+ if (nt->ntlength == nt->ntcapacity) {
+ if (nt->ntcapacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
PyErr_SetString(PyExc_MemoryError,
"overflow in nt_new");
return -1;
}
- self->ntcapacity *= 2;
- self->nt->nodes = realloc(self->nt->nodes,
- self->ntcapacity * sizeof(nodetreenode));
- if (self->nt->nodes == NULL) {
+ nt->ntcapacity *= 2;
+ nt->nodes = realloc(nt->nodes,
+ nt->ntcapacity * sizeof(nodetreenode));
+ if (nt->nodes == NULL) {
PyErr_SetString(PyExc_MemoryError, "out of memory");
return -1;
}
- memset(&self->nt->nodes[self->ntlength], 0,
- sizeof(nodetreenode) * (self->ntcapacity - self->ntlength));
+ memset(&nt->nodes[nt->ntlength], 0,
+ sizeof(nodetreenode) * (nt->ntcapacity - nt->ntlength));
}
- return self->ntlength++;
+ return nt->ntlength++;
}
static int nt_insert(indexObject *self, const char *node, int rev)
@@ -1072,9 +1073,9 @@
off = noff;
n = &self->nt->nodes[off];
n->children[nt_level(oldnode, ++level)] = v;
- if (level > self->ntdepth)
- self->ntdepth = level;
- self->ntsplits += 1;
+ if (level > self->nt->ntdepth)
+ self->nt->ntdepth = level;
+ self->nt->ntsplits += 1;
} else {
level += 1;
off = v;
@@ -1102,20 +1103,22 @@
PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
return -1;
}
- self->ntcapacity = self->raw_length < 4
+ self->nt->ntcapacity = self->raw_length < 4
? 4 : (int)self->raw_length / 2;
- self->nt->nodes = calloc(self->ntcapacity, sizeof(nodetreenode));
+ self->nt->nodes = calloc(self->nt->ntcapacity, sizeof(nodetreenode));
if (self->nt->nodes == NULL) {
free(self->nt);
self->nt = NULL;
PyErr_NoMemory();
return -1;
}
- self->ntlength = 1;
self->ntrev = (int)index_length(self);
self->ntlookups = 1;
self->ntmisses = 0;
+ self->nt->ntdepth = 0;
+ self->nt->ntsplits = 0;
+ self->nt->ntlength = 1;
if (nt_insert(self, nullid, -1) == -1) {
free(self->nt->nodes);
free(self->nt);
@@ -1982,8 +1985,6 @@
self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
self->data = data_obj;
- self->ntlength = self->ntcapacity = 0;
- self->ntdepth = self->ntsplits = 0;
self->ntlookups = self->ntmisses = 0;
self->ntrev = -1;
Py_INCREF(self->data);
To: martinvonz, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list