Mercurial > hg
comparison mercurial/cext/revlog.c @ 40706:0650be877a37
sparse-revlog: add a `trim_endidx` function in C
We are about to implement a native version of `slicechunktodensity`. For
clarity, we introduce the helper functions first.
This function implement a subpart of the python function `_trimchunk` in
`mercurial/revlogutils/deltas.py`. Handling of actual Python objects is left
to the caller function.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 09 Nov 2018 18:45:23 +0100 |
parents | 4ec6a24029d2 |
children | cc76ca9fca20 |
comparison
equal
deleted
inserted
replaced
40705:4ec6a24029d2 | 40706:0650be877a37 |
---|---|
1074 "between revisions (%zd) and (%zd)", | 1074 "between revisions (%zd) and (%zd)", |
1075 start_rev, end_rev); | 1075 start_rev, end_rev); |
1076 return -1; | 1076 return -1; |
1077 } | 1077 } |
1078 return (end_offset - start_offset) + (int64_t)end_size; | 1078 return (end_offset - start_offset) + (int64_t)end_size; |
1079 } | |
1080 | |
1081 /* returns revs[startidx:endidx] without empty trailing revs */ | |
1082 static Py_ssize_t trim_endidx(indexObject *self, const Py_ssize_t *revs, | |
1083 Py_ssize_t startidx, Py_ssize_t endidx) | |
1084 { | |
1085 int length; | |
1086 while (endidx > 1 && endidx > startidx) { | |
1087 length = index_get_length(self, revs[endidx - 1]); | |
1088 if (length < 0) { | |
1089 return -1; | |
1090 } | |
1091 if (length != 0) { | |
1092 break; | |
1093 } | |
1094 endidx -= 1; | |
1095 } | |
1096 return endidx; | |
1079 } | 1097 } |
1080 | 1098 |
1081 static inline int nt_level(const char *node, Py_ssize_t level) | 1099 static inline int nt_level(const char *node, Py_ssize_t level) |
1082 { | 1100 { |
1083 int v = node[level >> 1]; | 1101 int v = node[level >> 1]; |