From 71776bacccf51d0dc3abec48143f02c6452d3f8f Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Thu, 28 Nov 2013 00:00:28 +0800 Subject: [PATCH] Optimize TestFreeRow This commit has not fully tested yet. If you experience problems, please submit an issue. --- danmaku2ass.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/danmaku2ass.py b/danmaku2ass.py index f53c1b1..647d176 100755 --- a/danmaku2ass.py +++ b/danmaku2ass.py @@ -355,10 +355,12 @@ def TestFreeRows(rows, c, row, width, height, bottomReserved, lifetime): rowmax = height-bottomReserved-c[7] if c[4] in (1, 2): while row < rowmax and res < c[7]: - if rows[c[4]][row] and rows[c[4]][row][0]+lifetime > c[0]: + targetRow = rows[c[4]][row] + if targetRow and targetRow[0]+lifetime > c[0]: break - row += 1 - res += 1 + while rows[c[4]][row] == targetRow: + row += 1 + res += 1 else: try: thresholdTime = c[0]-lifetime*(1-width/(c[8]+width)) @@ -371,8 +373,9 @@ def TestFreeRows(rows, c, row, width, height, bottomReserved, lifetime): break except ZeroDivisionError: pass - row += 1 - res += 1 + while rows[c[4]][row] == targetRow: + row += 1 + res += 1 return res