##// END OF EJS Templates
fileset: optimize 'x and not y' to 'x - y'...
Yuya Nishihara -
r38868:ca4de8ba default
parent child Browse files
Show More
@@ -149,10 +149,12 def _analyze(x):
149 149 if op == 'not':
150 150 t = _analyze(x[1])
151 151 return (op, t)
152 if op in {'and', 'minus'}:
152 if op == 'and':
153 153 ta = _analyze(x[1])
154 154 tb = _analyze(x[2])
155 155 return (op, ta, tb)
156 if op == 'minus':
157 return _analyze(('and', x[1], ('not', x[2])))
156 158 if op in {'list', 'or'}:
157 159 ts = tuple(_analyze(y) for y in x[1:])
158 160 return (op,) + ts
@@ -171,6 +173,11 def analyze(x):
171 173 """
172 174 return _analyze(x)
173 175
176 def _optimizeandops(op, ta, tb):
177 if tb is not None and tb[0] == 'not':
178 return ('minus', ta, tb[1])
179 return (op, ta, tb)
180
174 181 def _optimize(x):
175 182 if x is None:
176 183 return 0, x
@@ -188,13 +195,9 def _optimize(x):
188 195 wa, ta = _optimize(x[1])
189 196 wb, tb = _optimize(x[2])
190 197 if wa <= wb:
191 return wa, (op, ta, tb)
198 return wa, _optimizeandops(op, ta, tb)
192 199 else:
193 return wb, (op, tb, ta)
194 if op == 'minus':
195 wa, ta = _optimize(x[1])
196 wb, tb = _optimize(x[2])
197 return max(wa, wb), (op, ta, tb)
200 return wb, _optimizeandops(op, tb, ta)
198 201 if op == 'or':
199 202 ws, ts = zip(*(_optimize(y) for y in x[1:]))
200 203 return max(ws), (op,) + ts
@@ -203,6 +203,73 Show parsed tree at stages:
203 203 b1
204 204 b2
205 205
206 Use differencematcher for 'x and not y':
207
208 $ fileset -p optimized -s 'a* and not a1'
209 * optimized:
210 (minus
211 (symbol 'a*')
212 (symbol 'a1'))
213 * matcher:
214 <differencematcher
215 m1=<patternmatcher patterns='(?:a[^/]*$)'>,
216 m2=<patternmatcher patterns='(?:a1$)'>>
217 a2
218
219 $ fileset -p optimized -s '!binary() and a*'
220 * optimized:
221 (minus
222 (symbol 'a*')
223 (func
224 (symbol 'binary')
225 None))
226 * matcher:
227 <differencematcher
228 m1=<patternmatcher patterns='(?:a[^/]*$)'>,
229 m2=<predicatenmatcher pred=binary>>
230 a1
231 a2
232
233 'x - y' is rewritten to 'x and not y' first so the operands can be reordered:
234
235 $ fileset -p analyzed -p optimized -s 'a* - a1'
236 * analyzed:
237 (and
238 (symbol 'a*')
239 (not
240 (symbol 'a1')))
241 * optimized:
242 (minus
243 (symbol 'a*')
244 (symbol 'a1'))
245 * matcher:
246 <differencematcher
247 m1=<patternmatcher patterns='(?:a[^/]*$)'>,
248 m2=<patternmatcher patterns='(?:a1$)'>>
249 a2
250
251 $ fileset -p analyzed -p optimized -s 'binary() - a*'
252 * analyzed:
253 (and
254 (func
255 (symbol 'binary')
256 None)
257 (not
258 (symbol 'a*')))
259 * optimized:
260 (and
261 (not
262 (symbol 'a*'))
263 (func
264 (symbol 'binary')
265 None))
266 * matcher:
267 <intersectionmatcher
268 m1=<predicatenmatcher
269 pred=<not
270 <patternmatcher patterns='(?:a[^/]*$)'>>>,
271 m2=<predicatenmatcher pred=binary>>
272
206 273 Test files status
207 274
208 275 $ rm a1
General Comments 0
You need to be logged in to leave comments. Login now