@@ -212,9 +212,6 @@ def update_test(ti: common.TestInfo):
212212 testlines = list (dict .fromkeys (testlines ))
213213 common .debug ("Valid test line found: " , len (testlines ))
214214
215- run_list_size = len (run_list )
216- testnum = len (testlines )
217-
218215 raw_output = []
219216 raw_prefixes = []
220217 for (
@@ -256,60 +253,47 @@ def update_test(ti: common.TestInfo):
256253 prefix_set = set ([prefix for p in run_list for prefix in p [0 ]])
257254 common .debug ("Rewriting FileCheck prefixes:" , str (prefix_set ))
258255
259- for test_id in range (testnum ):
260- input_line = testlines [test_id ]
261-
256+ for test_id , input_line in enumerate (testlines ):
262257 # a {prefix : output, [runid] } dict
263258 # insert output to a prefix-key dict, and do a max sorting
264259 # to select the most-used prefix which share the same output string
265260 p_dict = {}
266- for run_id in range (run_list_size ):
261+ for run_id in range (len ( run_list ) ):
267262 out = raw_output [run_id ][test_id ]
268263
269264 if hasErr (out ):
270265 o = getErrString (out )
271266 else :
272267 o = getOutputString (out )
273268
274- prefixes = raw_prefixes [run_id ]
275-
276- for p in prefixes :
269+ for p in raw_prefixes [run_id ]:
277270 if p not in p_dict :
278271 p_dict [p ] = o , [run_id ]
279- else :
280- if p_dict [p ] == (None , []):
281- continue
272+ continue
282273
283- prev_o , run_ids = p_dict [p ]
284- if o == prev_o :
285- run_ids .append (run_id )
286- p_dict [p ] = o , run_ids
287- else :
288- # conflict, discard
289- p_dict [p ] = None , []
274+ if p_dict [p ] == (None , []):
275+ continue
290276
291- p_dict_sorted = dict (sorted (p_dict .items (), key = lambda item : - len (item [1 ][1 ])))
277+ prev_o , run_ids = p_dict [p ]
278+ if o == prev_o :
279+ run_ids .append (run_id )
280+ p_dict [p ] = o , run_ids
281+ else :
282+ # conflict, discard
283+ p_dict [p ] = None , []
292284
293285 # prefix is selected and generated with most shared output lines
294286 # each run_id can only be used once
295- used_runid = set ()
296-
287+ used_run_ids = set ()
297288 selected_prefixes = set ()
298- for prefix , tup in p_dict_sorted .items ():
299- o , run_ids = tup
300-
301- if len (run_ids ) == 0 :
302- continue
303-
304- skip = False
305- for i in run_ids :
306- if i in used_runid :
307- skip = True
308- else :
309- used_runid .add (i )
310- if not skip :
289+ get_num_runs = lambda item : len (item [1 ][1 ])
290+ p_dict_sorted = sorted (p_dict .items (), key = get_num_runs , reverse = True )
291+ for prefix , (o , run_ids ) in p_dict_sorted :
292+ if run_ids and used_run_ids .isdisjoint (run_ids ):
311293 selected_prefixes .add (prefix )
312294
295+ used_run_ids .update (run_ids )
296+
313297 # Generate check lines in alphabetical order.
314298 check_lines = []
315299 for prefix in sorted (selected_prefixes ):
0 commit comments