##// END OF EJS Templates
index: move more fields onto nodetree type...
Martin von Zweigbergk -
r38949:c2c25355 default
parent child Browse files
Show More
@@ -41,6 +41,10 b' typedef struct {'
41 41 */
42 42 typedef struct {
43 43 nodetreenode *nodes;
44 unsigned ntlength; /* # nodes in use */
45 unsigned ntcapacity; /* # nodes allocated */
46 int ntdepth; /* maximum depth of tree */
47 int ntsplits; /* # splits performed */
44 48 } nodetree;
45 49
46 50 /*
@@ -68,10 +72,6 b' typedef struct {'
68 72 PyObject *headrevs; /* cache, invalidated on changes */
69 73 PyObject *filteredrevs;/* filtered revs set */
70 74 nodetree *nt; /* base-16 trie */
71 unsigned ntlength; /* # nodes in use */
72 unsigned ntcapacity; /* # nodes allocated */
73 int ntdepth; /* maximum depth of tree */
74 int ntsplits; /* # splits performed */
75 75 int ntrev; /* last rev scanned */
76 76 int ntlookups; /* # lookups */
77 77 int ntmisses; /* # lookups that miss the cache */
@@ -332,8 +332,6 b' static void _index_clearcaches(indexObje'
332 332 static PyObject *index_clearcaches(indexObject *self)
333 333 {
334 334 _index_clearcaches(self);
335 self->ntlength = self->ntcapacity = 0;
336 self->ntdepth = self->ntsplits = 0;
337 335 self->ntrev = -1;
338 336 self->ntlookups = self->ntmisses = 0;
339 337 Py_RETURN_NONE;
@@ -370,13 +368,15 b' static PyObject *index_stats(indexObject'
370 368 if (self->raw_length != self->length - 1)
371 369 istat(raw_length, "revs on disk");
372 370 istat(length, "revs in memory");
373 istat(ntcapacity, "node trie capacity");
374 istat(ntdepth, "node trie depth");
375 istat(ntlength, "node trie count");
376 371 istat(ntlookups, "node trie lookups");
377 372 istat(ntmisses, "node trie misses");
378 373 istat(ntrev, "node trie last rev scanned");
379 istat(ntsplits, "node trie splits");
374 if (self->nt) {
375 istat(nt->ntcapacity, "node trie capacity");
376 istat(nt->ntdepth, "node trie depth");
377 istat(nt->ntlength, "node trie count");
378 istat(nt->ntsplits, "node trie splits");
379 }
380 380
381 381 #undef istat
382 382
@@ -1017,23 +1017,24 b' static int nt_find(indexObject *self, co'
1017 1017
1018 1018 static int nt_new(indexObject *self)
1019 1019 {
1020 if (self->ntlength == self->ntcapacity) {
1021 if (self->ntcapacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
1020 nodetree *nt = self->nt;
1021 if (nt->ntlength == nt->ntcapacity) {
1022 if (nt->ntcapacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
1022 1023 PyErr_SetString(PyExc_MemoryError,
1023 1024 "overflow in nt_new");
1024 1025 return -1;
1025 1026 }
1026 self->ntcapacity *= 2;
1027 self->nt->nodes = realloc(self->nt->nodes,
1028 self->ntcapacity * sizeof(nodetreenode));
1029 if (self->nt->nodes == NULL) {
1027 nt->ntcapacity *= 2;
1028 nt->nodes = realloc(nt->nodes,
1029 nt->ntcapacity * sizeof(nodetreenode));
1030 if (nt->nodes == NULL) {
1030 1031 PyErr_SetString(PyExc_MemoryError, "out of memory");
1031 1032 return -1;
1032 1033 }
1033 memset(&self->nt->nodes[self->ntlength], 0,
1034 sizeof(nodetreenode) * (self->ntcapacity - self->ntlength));
1034 memset(&nt->nodes[nt->ntlength], 0,
1035 sizeof(nodetreenode) * (nt->ntcapacity - nt->ntlength));
1035 1036 }
1036 return self->ntlength++;
1037 return nt->ntlength++;
1037 1038 }
1038 1039
1039 1040 static int nt_insert(indexObject *self, const char *node, int rev)
@@ -1071,9 +1072,9 b' static int nt_insert(indexObject *self, '
1071 1072 off = noff;
1072 1073 n = &self->nt->nodes[off];
1073 1074 n->children[nt_level(oldnode, ++level)] = v;
1074 if (level > self->ntdepth)
1075 self->ntdepth = level;
1076 self->ntsplits += 1;
1075 if (level > self->nt->ntdepth)
1076 self->nt->ntdepth = level;
1077 self->nt->ntsplits += 1;
1077 1078 } else {
1078 1079 level += 1;
1079 1080 off = v;
@@ -1101,20 +1102,22 b' static int nt_init(indexObject *self)'
1101 1102 PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
1102 1103 return -1;
1103 1104 }
1104 self->ntcapacity = self->raw_length < 4
1105 self->nt->ntcapacity = self->raw_length < 4
1105 1106 ? 4 : (int)self->raw_length / 2;
1106 1107
1107 self->nt->nodes = calloc(self->ntcapacity, sizeof(nodetreenode));
1108 self->nt->nodes = calloc(self->nt->ntcapacity, sizeof(nodetreenode));
1108 1109 if (self->nt->nodes == NULL) {
1109 1110 free(self->nt);
1110 1111 self->nt = NULL;
1111 1112 PyErr_NoMemory();
1112 1113 return -1;
1113 1114 }
1114 self->ntlength = 1;
1115 1115 self->ntrev = (int)index_length(self);
1116 1116 self->ntlookups = 1;
1117 1117 self->ntmisses = 0;
1118 self->nt->ntdepth = 0;
1119 self->nt->ntsplits = 0;
1120 self->nt->ntlength = 1;
1118 1121 if (nt_insert(self, nullid, -1) == -1) {
1119 1122 free(self->nt->nodes);
1120 1123 free(self->nt);
@@ -1981,8 +1984,6 b' static int index_init(indexObject *self,'
1981 1984 self->inlined = inlined_obj && PyObject_IsTrue(inlined_obj);
1982 1985 self->data = data_obj;
1983 1986
1984 self->ntlength = self->ntcapacity = 0;
1985 self->ntdepth = self->ntsplits = 0;
1986 1987 self->ntlookups = self->ntmisses = 0;
1987 1988 self->ntrev = -1;
1988 1989 Py_INCREF(self->data);
General Comments 0
You need to be logged in to leave comments. Login now