A.Politz schrieb:
> todo.txt :
> 9   HTML indenting can be slow.  Caused by using searchpair().  Can
>     search() be used instead?
> 
> (Is this up to date ? If not you can skip the rest ;-) )
> 
> In fact html indenting can be dramatically slow. For example try to
> indent this page http://www.weather.com/weather/local/USPA0372 .It
> needs 10 minutes on my machine, for ~4000 lines.  As the todo item
> states, this is caused by the 4 searchpair() calls in
> indent/html.vim, of which 3 are called for nearly every line. In the,
> very likely, worst-case the whole buffer is searched multiple times
> and it increases somewhat quadratic for every additional line (which
> has to be searched and which triggers a new search ).  It looks like
> using searchpair() in this way in an indent file is a very bad idea.
> 
> I attached a file, which is not a patch, but contains 2 different
> foldfuncs (the old and a new one ) and a mapping on <f3> to toggle
> between them.Instead of searchpair(), the 2nd function pre scans the
> buffer for <script> and <pre> tags and stores the lines in a dict,
> which is later used to determine the indent for this tags.  It also
> indents this tags homogeneously.
> 
> I also thought about,whether searchpair() could benefit from some
> memory. This would obviously very volatile, a single change of the
> buffer and it could not be trusted anymore.  Well, I thought I make
> a quick implementation in vimscript and if it isn't at least as
> quick as without it, it could be worth the trouble. But it didn't
> work out, though I hit the bucket 1/3 of the times (Using htmlindent).
> 
> -ap

Another idea:

The indent function is called in succession for every line to be
indented.  This fact should be considered --

After the indent for a line is calculated, a state should be remembered
(line number, line is within a <pre> block yes/no, etc.; also for
safety: computed indent, the first word of the line, etc.).

A call to the indent function should first check if it is a
"continuation call":
    IF there is a state
        and if remembered_lnum+1 == v:lnum
        and (maybe for safety)
            if remembered_indent == indent(remembered_lnum)
        and              ...

    THEN start calculation at the remembered state, else start from
        scratch (as it works now).

Such a mechanism could make sure that searchpair() is only called when
really needed.

Problem: I haven't tried it yet ...

-- 
Andy

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui