@@ -222,9 +222,6 @@ def update_test(ti: common.TestInfo):
222222 testlines = list (dict .fromkeys (testlines ))
223223 common .debug ("Valid test line found: " , len (testlines ))
224224
225- run_list_size = len (run_list )
226- testnum = len (testlines )
227-
228225 raw_output = []
229226 raw_prefixes = []
230227 for (
@@ -266,60 +263,47 @@ def update_test(ti: common.TestInfo):
266263 prefix_set = set ([prefix for p in run_list for prefix in p [0 ]])
267264 common .debug ("Rewriting FileCheck prefixes:" , str (prefix_set ))
268265
269- for test_id in range (testnum ):
270- input_line = testlines [test_id ]
271-
266+ for test_id , input_line in enumerate (testlines ):
272267 # a {prefix : output, [runid] } dict
273268 # insert output to a prefix-key dict, and do a max sorting
274269 # to select the most-used prefix which share the same output string
275270 p_dict = {}
276- for run_id in range (run_list_size ):
271+ for run_id in range (len ( run_list ) ):
277272 out = raw_output [run_id ][test_id ]
278273
279274 if hasErr (out ):
280275 o = getErrString (out )
281276 else :
282277 o = getOutputString (out )
283278
284- prefixes = raw_prefixes [run_id ]
285-
286- for p in prefixes :
279+ for p in raw_prefixes [run_id ]:
287280 if p not in p_dict :
288281 p_dict [p ] = o , [run_id ]
289- else :
290- if p_dict [p ] == (None , []):
291- continue
282+ continue
292283
293- prev_o , run_ids = p_dict [p ]
294- if o == prev_o :
295- run_ids .append (run_id )
296- p_dict [p ] = o , run_ids
297- else :
298- # conflict, discard
299- p_dict [p ] = None , []
284+ if p_dict [p ] == (None , []):
285+ continue
300286
301- p_dict_sorted = dict (sorted (p_dict .items (), key = lambda item : - len (item [1 ][1 ])))
287+ prev_o , run_ids = p_dict [p ]
288+ if o == prev_o :
289+ run_ids .append (run_id )
290+ p_dict [p ] = o , run_ids
291+ else :
292+ # conflict, discard
293+ p_dict [p ] = None , []
302294
303295 # prefix is selected and generated with most shared output lines
304296 # each run_id can only be used once
305- used_runid = set ()
306-
297+ used_run_ids = set ()
307298 selected_prefixes = set ()
308- for prefix , tup in p_dict_sorted .items ():
309- o , run_ids = tup
310-
311- if len (run_ids ) == 0 :
312- continue
313-
314- skip = False
315- for i in run_ids :
316- if i in used_runid :
317- skip = True
318- else :
319- used_runid .add (i )
320- if not skip :
299+ get_num_runs = lambda item : len (item [1 ][1 ])
300+ p_dict_sorted = sorted (p_dict .items (), key = get_num_runs , reverse = True )
301+ for prefix , (o , run_ids ) in p_dict_sorted :
302+ if run_ids and used_run_ids .isdisjoint (run_ids ):
321303 selected_prefixes .add (prefix )
322304
305+ used_run_ids .update (run_ids )
306+
323307 # Generate check lines in alphabetical order.
324308 check_lines = []
325309 for prefix in sorted (selected_prefixes ):
0 commit comments