Show More
@@ -772,6 +772,16 class generatorset(abstractsmartset): | |||
|
772 | 772 | >>> xs.last() # cached |
|
773 | 773 | 4 |
|
774 | 774 | """ |
|
775 | def __new__(cls, gen, iterasc=None): | |
|
776 | if iterasc is None: | |
|
777 | typ = cls | |
|
778 | elif iterasc: | |
|
779 | typ = _generatorsetasc | |
|
780 | else: | |
|
781 | typ = _generatorsetdesc | |
|
782 | ||
|
783 | return super(generatorset, cls).__new__(typ) | |
|
784 | ||
|
775 | 785 | def __init__(self, gen, iterasc=None): |
|
776 | 786 | """ |
|
777 | 787 | gen: a generator producing the values for the generatorset. |
@@ -782,13 +792,6 class generatorset(abstractsmartset): | |||
|
782 | 792 | self._genlist = [] |
|
783 | 793 | self._finished = False |
|
784 | 794 | self._ascending = True |
|
785 | if iterasc is not None: | |
|
786 | if iterasc: | |
|
787 | self.fastasc = self._iterator | |
|
788 | self.__contains__ = self._asccontains | |
|
789 | else: | |
|
790 | self.fastdesc = self._iterator | |
|
791 | self.__contains__ = self._desccontains | |
|
792 | 795 | |
|
793 | 796 | def __nonzero__(self): |
|
794 | 797 | # Do not use 'for r in self' because it will enforce the iteration |
@@ -814,36 +817,6 class generatorset(abstractsmartset): | |||
|
814 | 817 | self._cache[x] = False |
|
815 | 818 | return False |
|
816 | 819 | |
|
817 | def _asccontains(self, x): | |
|
818 | """version of contains optimised for ascending generator""" | |
|
819 | if x in self._cache: | |
|
820 | return self._cache[x] | |
|
821 | ||
|
822 | # Use new values only, as existing values would be cached. | |
|
823 | for l in self._consumegen(): | |
|
824 | if l == x: | |
|
825 | return True | |
|
826 | if l > x: | |
|
827 | break | |
|
828 | ||
|
829 | self._cache[x] = False | |
|
830 | return False | |
|
831 | ||
|
832 | def _desccontains(self, x): | |
|
833 | """version of contains optimised for descending generator""" | |
|
834 | if x in self._cache: | |
|
835 | return self._cache[x] | |
|
836 | ||
|
837 | # Use new values only, as existing values would be cached. | |
|
838 | for l in self._consumegen(): | |
|
839 | if l == x: | |
|
840 | return True | |
|
841 | if l < x: | |
|
842 | break | |
|
843 | ||
|
844 | self._cache[x] = False | |
|
845 | return False | |
|
846 | ||
|
847 | 820 | def __iter__(self): |
|
848 | 821 | if self._ascending: |
|
849 | 822 | it = self.fastasc |
@@ -947,7 +920,45 class generatorset(abstractsmartset): | |||
|
947 | 920 | |
|
948 | 921 | def __repr__(self): |
|
949 | 922 | d = {False: '-', True: '+'}[self._ascending] |
|
950 | return '<%s%s>' % (type(self).__name__, d) | |
|
923 | return '<%s%s>' % (type(self).__name__.lstrip('_'), d) | |
|
924 | ||
|
925 | class _generatorsetasc(generatorset): | |
|
926 | """Special case of generatorset optimized for ascending generators.""" | |
|
927 | ||
|
928 | fastasc = generatorset._iterator | |
|
929 | ||
|
930 | def __contains__(self, x): | |
|
931 | if x in self._cache: | |
|
932 | return self._cache[x] | |
|
933 | ||
|
934 | # Use new values only, as existing values would be cached. | |
|
935 | for l in self._consumegen(): | |
|
936 | if l == x: | |
|
937 | return True | |
|
938 | if l > x: | |
|
939 | break | |
|
940 | ||
|
941 | self._cache[x] = False | |
|
942 | return False | |
|
943 | ||
|
944 | class _generatorsetdesc(generatorset): | |
|
945 | """Special case of generatorset optimized for descending generators.""" | |
|
946 | ||
|
947 | fastdesc = generatorset._iterator | |
|
948 | ||
|
949 | def __contains__(self, x): | |
|
950 | if x in self._cache: | |
|
951 | return self._cache[x] | |
|
952 | ||
|
953 | # Use new values only, as existing values would be cached. | |
|
954 | for l in self._consumegen(): | |
|
955 | if l == x: | |
|
956 | return True | |
|
957 | if l < x: | |
|
958 | break | |
|
959 | ||
|
960 | self._cache[x] = False | |
|
961 | return False | |
|
951 | 962 | |
|
952 | 963 | def spanset(repo, start=0, end=None): |
|
953 | 964 | """Create a spanset that represents a range of repository revisions |
@@ -1484,7 +1484,7 Test scmutil.revsingle() should return t | |||
|
1484 | 1484 | $ hg debugrevspec -s 'last(0::)' |
|
1485 | 1485 | * set: |
|
1486 | 1486 | <baseset slice=0:1 |
|
1487 | <generatorset->> | |
|
1487 | <generatorsetasc->> | |
|
1488 | 1488 | 9 |
|
1489 | 1489 | $ hg identify -r '0::' --num |
|
1490 | 1490 | 9 |
@@ -152,7 +152,7 test that `or` operation skips duplicate | |||
|
152 | 152 | * set: |
|
153 | 153 | <addset |
|
154 | 154 | <baseset- [1, 3, 5]>, |
|
155 | <generatorset+>> | |
|
155 | <generatorsetdesc+>> | |
|
156 | 156 | 5 |
|
157 | 157 | 3 |
|
158 | 158 | 1 |
@@ -174,7 +174,7 test that `or` operation skips duplicate | |||
|
174 | 174 | (symbol '5')))))) |
|
175 | 175 | * set: |
|
176 | 176 | <addset+ |
|
177 | <generatorset+>, | |
|
177 | <generatorsetdesc+>, | |
|
178 | 178 | <baseset- [1, 3, 5]>> |
|
179 | 179 | 0 |
|
180 | 180 | 1 |
@@ -927,7 +927,7 test alias recursion | |||
|
927 | 927 | (symbol 'merge') |
|
928 | 928 | None)) |
|
929 | 929 | * set: |
|
930 | <generatorset+> | |
|
930 | <generatorsetasc+> | |
|
931 | 931 | 6 |
|
932 | 932 | 7 |
|
933 | 933 |
General Comments 0
You need to be logged in to leave comments.
Login now