TypesettingTools / Aegisub-Motion

Lua plugin for Aegisub auto4 that parses motion tracking data and applies it to selected subtitles.
Other
174 stars 24 forks source link

Speedup & cosmetics #3

Closed tophf closed 10 years ago

tophf commented 10 years ago
tophf commented 10 years ago

I should talk to plorkyeran about a version that takes an array of indices rather than a list of arguments.

So now subs.delete is added which is good but:

  1. no _subs.insert index, table_oflines yet
  2. to support the existing Aegisub 3.x versions you'll have to wrap it in pcall as well as keep the existing code
    ok, _ = pcall sub.delete sel
    ok, _ = pcall -> sub.delete unpack sel unless ok
    if not ok --pay the price
        for i = #sel, 1, -1
            sub.delete sel[i] -- BALEET (in reverse because they are not necessarily contiguous)
            check_user_cancelled!

    ok, _ = pcall -> sub.insert strt, unpack [v.data for v in *lines]
    if not ok --pay the price
        for i, v in ipairs lines
            aegisub.progress.set i/#lines*100
            sub.insert strt, v.data -- not sure this is the best place to do this but owell
            strt += 1
            check_user_cancelled!
torque commented 10 years ago

I didn't even notice subs.insert(start, line1, line2, ...) existed. I wonder if that would be more efficient than inserting 1-by-1, though, because I imagine Lua has to copy memory around every time you insert an index into a table, which would get expensive with a big table full of dialog line tables.

That said, it would make sense for symmetric syntax to exist, and I could be wrong about it being slower, anyway.

tophf commented 10 years ago

You could be right. But we can try to reorganize processing of the 'lines' table like this (when and if subs.insert is extended):

    sortF = ({
        Time:   (l, n) ->
            l.key, l.num = l.start_time, n
            l
        ...................
    })[sor]
    ...................
    ok, _ = pcall sub.insert strt, lines
    if not ok --pay the price
        for i, v in ipairs lines
            aegisub.progress.set i/#lines*100
            sub.insert strt, v
            strt += 1
            check_user_cancelled!