Brad Beveridge wrote:

> > I wonder how you create a new line.  Using the old mechanism you mostly
> > end up reallocating the line at the next insert.  Allocating a bit of
> > room to anticipate further appends would be more efficient.
> I'm sorry, I don't understand quite what you mean with that comment.
> Do you mean "if you only used ml_append_string, how do new lines ever
> get created?"  If you do mean that, then the answer is: new lines need
> to be created by an upper level function.  I have an upper level
> "append_char" function that is more or less:
> void append_char (buf, char) {
>   static uchar string[2] = {0};
>   curbuf = buf;
>   if (char == '\n')
>      ml_append // create a new line
>   else
>      {
>         string[0] = char;
>         ml_append_string (string)
> .......
> The reason that I didn't do new line creation in append_string is that
> you would need to check all incoming strings for newlines, the upper
> level layers can better do this check because they have more
> information about the incoming string - they could know it will never
> contain newlines.

I understand.  It would be a bit more efficient if the new, empty line
that you add when a newline is encountered already has room for a
certain number of characters.
 
> > Also, for appending to a different line than before you copy the line
> > twice.  You can avoid that by using vim_strnsave() instead of
> > vim_strsave() and reserving space for new characters right away.
> 
> Yes, this is a slight inefficiency.  The main reason that I did this
> was that I wanted all the code to do with re-allocation in the same
> place, ie the next if block.  Looking at the code again now, the
> solution is probably to not copy in the "cache miss" code, where we
> flush - just do
> curbuf->b_ml.ml_line_ptr = ml_get(lnum);

I suppose that should work (didn't look at it carefully).

I might have a look later if this code can be used in certain
situations.  That should make some operations work faster, e.g. pasting
a large chunk of text into a terminal emulator.

-- 
Some of the well know MS-Windows errors:
        EMULTI          Multitasking attempted, system confused
        EKEYBOARD       Keyboard locked, try getting out of this one!
        EXPLAIN         Unexplained error, please tell us what happened
        EFUTURE         Reserved for our future mistakes

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to