Had LST used <section name=foo> </section> to mark sections,
instead of <section begin=foo />content<section end=foo />, it
would be as easy as traversing the preprocessor output, which would
already have the sections splitted.

Alex Brollo wrote:
> 2011/1/25 Alex Brollo <alex.bro...@gmail.com>
> 
> Just to test effectiveness of such a strange idea, I added some formal
> section tags into a 6 Kby text section.txt, then I wrote a simple script to
> create a "data area" , this is the result (a python dictionary into a html
> comment code) appended to the section.txt file:
> 
> <!--SECTIONS:{'<section begin=1 />': [(152, 990), (1282, 2406), (4078,
> 4478)], '<section begin=6 />': [(19, 115)], '<section begin=2 />': [(2443,
> 2821), (2859, 3256)], '<section begin=4 />': [(1555, 1901)], '<section
> begin=5 />': [(171, 477)], '<section begin=3 />': [(3704, 4042)]}-->
> 
> then I run these lines from python idle:
> 
>>>> for i in range(1000):
>     f=open("section.txt").read()
>     indici=eval(find_stringa(f,"<!--SECTIONS:","-->"))
>     t=""
>     for i in indici["<section begin=1 />"]:
>         t+=f[i[0]:i[1]]
> 
> As you see the code, for 1000 times:
> opens the file and loads it
> selects "data area" (find_stringa is a personal, string seach tool to get
> strings), and converts it into a dictionary
> retrieves all the text inside multiple sections named "1" (the worst case in
> the list: section 1 has three instances: [(152, 990), (1282, 2406), (4078,
> 4478)]
> 
> Time to do 1000 cicles: more or less, 3 seconds on a far from powerful pc.
> :-)
> Fast, in my opinion!
> 
> So, it can be done, and it runs, in an effective way too. Doesn't it?
> 
> Alex

It can obviously be done. But you should compare it against the original
implementation. 3 seconds by itself isn't meaningful.
Another thing to test would be using stripos() instead of those regex,
in case it is faster.


_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to