On Thursday, November 4, 2021 at 10:17:35 AM UTC-5 Edward K. Ream wrote:

> On Thu, Nov 4, 2021 at 9:28 AM [email protected] <[email protected]> 
> wrote:
>

 >> But is this really the case, or is this a case of premature 
optimization? 
> leoPy.leo contains 411 files. Speed matters here, even a few percentage 
points.

Let me attempt a better answer.

I don't know what the slowdown would be if the code used function calls 
instead of sections. But the performance question is moot because imo the 
present code is the clearest possible code.

Indeed, the << init scan_lines >> section defines a *lot* of state 
variables. It would be clumsy (and a maybe slow) to be passing these state 
variables to helper functions.  Sure, we could use stat *ivars* instead...

But the main point is that the present code highlights the structure of the 
code pretty well.  The meta pattern of the main loop is:

if << a condition >>:
    << handle the line >>
    continue

or sometimes:

if << a condition >>:
    << handle the line >>
    continue
else:
    << do something else >>
    continue

Some sections contain both the condition and the continue statement, so the 
pattern isn't quite as clear as it could be. I've chosen to "render" the 
sections as I have to highlight conditions that are *not* simply pattern 
matches. The explicitly shown tests are those that confused me the most 
while I was reacquainting myself with the code. 

Anyway, each handler deals with only a small subset of all the state 
variables, so the code, while hardly trivial, is *relatively* easy to 
understand.

*Summary*

I could say more, but I think I've said enough :-)

Imo, the present code is likely the fastest possible code and the clearest 
possible code. Hard to do better than that.

Edward

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/f9ce75ea-b880-4632-a0b8-fd69aadb273an%40googlegroups.com.

Reply via email to