Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cext/revlog.c @ 40300:72b94f946e90
rust: rustlazyancestors.__contains__
This changeset provides a Rust implementation of
the iteration performed by lazyancestor.__contains__
It has the advantage over the Python iteration to use
the 'seen' set encapsuled into the dedicated iterator (self._containsiter),
rather than storing emitted items in another set (self._containsseen),
and hence should reduce the memory footprint.
Also, there's no need to convert intermediate emitted revisions back into
Python integers.
At this point, it would be tempting to implement the whole lazyancestor object
in Rust, but that would lead to more C wrapping code (two objects) for
little expected benefits.
author | Georges Racinet <gracinet@anybox.fr> |
---|---|
date | Mon, 08 Oct 2018 19:11:41 +0200 |
parents | 3b275f549777 |
children | a91a2837150b 88702fd208ce |
line wrap: on
line diff
--- a/mercurial/cext/revlog.c Sun Oct 14 01:39:22 2018 -0400 +++ b/mercurial/cext/revlog.c Mon Oct 08 19:11:41 2018 +0200 @@ -2316,6 +2316,7 @@ int inclusive); void rustlazyancestors_drop(rustlazyancestorsObject *self); int rustlazyancestors_next(rustlazyancestorsObject *self); +int rustlazyancestors_contains(rustlazyancestorsObject *self, long rev); /* CPython instance methods */ static int rustla_init(rustlazyancestorsObject *self, @@ -2395,6 +2396,24 @@ return PyInt_FromLong(res); } +static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev) { + if (!(PyInt_Check(rev))) { + return 0; + } + return rustlazyancestors_contains(self->iter, PyInt_AS_LONG(rev)); +} + +static PySequenceMethods rustla_sequence_methods = { + 0, /* sq_length */ + 0, /* sq_concat */ + 0, /* sq_repeat */ + 0, /* sq_item */ + 0, /* sq_slice */ + 0, /* sq_ass_item */ + 0, /* sq_ass_slice */ + (objobjproc)rustla_contains, /* sq_contains */ +}; + static PyTypeObject rustlazyancestorsType = { PyVarObject_HEAD_INIT(NULL, 0) /* header */ "parsers.rustlazyancestors", /* tp_name */ @@ -2407,7 +2426,7 @@ 0, /* tp_compare */ 0, /* tp_repr */ 0, /* tp_as_number */ - 0, /* tp_as_sequence */ + &rustla_sequence_methods, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */