enthought / enaml

Default Repo description from terraform module
Other
3 stars 0 forks source link

Add eliding to grid headers #254

Closed nmichaud closed 11 years ago

nmichaud commented 11 years ago

Add text eliding to grid headers

sccolbert commented 11 years ago

Yes I just meant the if expression; it never changes throughout the entire iteration of the loop, so you are computing the same thing over-and-over for no reason: http://en.wikipedia.org/wiki/Loop-invariant_code_motion

A good compiler will refactor this for you as part of the optimization pass. We don't get that with Python. So I'm suggesting you do the equivalent of the following.

Convert this:

for i in range(N):
    if foo:
        bar()
    else:
        baz()

Into this:

if foo:
    for i in range(N):
        bar()
else:
    for i in range(N):
        baz()

That latter is 1 comparison vs N comparisons.

nmichaud commented 11 years ago

OK, that's what I suspected you meant. I just didn't know if you wanted to expand the code that much - as you say, python's default interpreter isn't able to optimize that away. I'll fix it in a new commit.

sccolbert commented 11 years ago

you don't have to pull it out of the outermost loop which is looping over in the invalid rects, which is small in number. But I think it'd be worth it in the inner loop, if only for the sake of being proper.

On Wed, Feb 6, 2013 at 10:21 PM, nmichaud notifications@github.com wrote:

OK, that's what I suspected you meant. I just didn't know if you wanted to expand the code that much - as you say, python's default interpreter isn't able to optimize that away. I'll fix it in a new commit.

— Reply to this email directly or view it on GitHubhttps://github.com/enthought/enaml/pull/254#issuecomment-13219316.