I don't (yet) know if this matters, but the second function is about three 
times faster than 'computeWidth'. It would be even five times as fast 
without the 'split' command that accounts for the # Bug fix: 2012/06/05. 
The 'expandtabs' function of Python automatically takes care of the 
variable tab distances.


def computeWidth(s, tab_width):
    # from leoGlobals.py
    w = 0
    for ch in s:
        if ch == '\t':
            w += (abs(tab_width) - (w % abs(tab_width)))
        else:
            w += 1
    return w

def computeWidth2(s, tab_width):
    return len(s.split("\n")[0].expandtabs(abs(tab_width)))

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to