annotate mercurial/strutil.py @ 23724:aafeaba22826 stable

revset: drop pre-lazyset optimization for stringset of subset == entire repo It was introduced at e44ebd2a142a, where spanset.__contains__() did not exist. Nowadays, we have to pay huge penalty for len(subset). The following example showed that OR operation could be O(n * m^2) (n: len(repo), m: number of OR operators, m >= 2) probably because of filteredset.__len__. revset #0: 0|1|2|3|4|5|6|7|8|9 0) wall 8.092713 comb 8.090000 user 8.090000 sys 0.000000 (best of 3) 1) wall 0.445354 comb 0.450000 user 0.430000 sys 0.020000 (best of 22) 2) wall 0.000389 comb 0.000000 user 0.000000 sys 0.000000 (best of 7347) (0: 3.2.4, 1: 3.1.2, 2: this patch)
author Yuya Nishihara <yuya@tcha.org>
date Sat, 03 Jan 2015 10:25:08 +0900
parents 25e572394f5c
children b723f05ec49b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1 # strutil.py - string utilities for Mercurial
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
2 #
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
3 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
4 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8155
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8225
diff changeset
6 # GNU General Public License version 2 or any later version.
2953
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
7
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
8 def findall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
9 if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
10 end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
11 if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
12 end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
13 if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
14 start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
15 while start < end:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
16 c = haystack.find(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
17 if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
18 break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
19 yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
20 start = c + 1
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
21
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
22 def rfindall(haystack, needle, start=0, end=None):
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
23 if end is None:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
24 end = len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
25 if end < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
26 end += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
27 if start < 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
28 start += len(haystack)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
29 while end >= 0:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
30 c = haystack.rfind(needle, start, end)
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
31 if c == -1:
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
32 break
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
33 yield c
3d5547845158 fix issue 322.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
34 end = c - 1