patch 9.0.0634: evaluating "expr" options has more overhead than needed

Problem:    Evaluating "expr" options has more overhead than needed.
Solution:   Use call_simple_func() for 'foldtext', 'includeexpr', 'printexpr',
            "expr" of 'spellsuggest', 'diffexpr', 'patchexpr', 'balloonexpr',
            'formatexpr', 'indentexpr' and 'charconvert'.
This commit is contained in:
Bram Moolenaar
2022-10-01 19:43:52 +01:00
parent b850c39676
commit a4e0b9785e
24 changed files with 174 additions and 74 deletions

View File

@ -1626,6 +1626,9 @@ A jump table for the options with a short description can be found at |Q_op|.
Note that v:charconvert_from and v:charconvert_to may be different
from 'encoding'. Vim internally uses UTF-8 instead of UCS-2 or UCS-4.
The advantage of using a function call without arguments is that it is
faster, see |expr-option-function|.
Encryption is not done by Vim when using 'charconvert'. If you want
to encrypt the file after conversion, 'charconvert' should take care
of this.
@ -3664,6 +3667,9 @@ A jump table for the options with a short description can be found at |Q_op|.
< This will invoke the mylang#Format() function in the
autoload/mylang.vim file in 'runtimepath'. |autoload|
The advantage of using a function call without arguments is that it is
faster, see |expr-option-function|.
The expression is also evaluated when 'textwidth' is set and adding
text beyond that limit. This happens under the same conditions as
when internal formatting is used. Make sure the cursor is kept in the
@ -4534,11 +4540,14 @@ A jump table for the options with a short description can be found at |Q_op|.
If the expression starts with s: or |<SID>|, then it is replaced with
the script ID (|local-function|). Example: >
set includeexpr=s:MyIncludeExpr(v:fname)
set includeexpr=<SID>SomeIncludeExpr(v:fname)
set includeexpr=s:MyIncludeExpr()
set includeexpr=<SID>SomeIncludeExpr()
< Otherwise, the expression is evaluated in the context of the script
where the option was set, thus script-local items are available.
It is more efficient if the value is just a function call without
arguments, see |expr-option-function|.
The expression will be evaluated in the |sandbox| when set from a
modeline, see |sandbox-option|.
This option cannot be set in a modeline when 'modelineexpr' is off.
@ -4620,6 +4629,9 @@ A jump table for the options with a short description can be found at |Q_op|.
< Otherwise, the expression is evaluated in the context of the script
where the option was set, thus script-local items are available.
The advantage of using a function call without arguments is that it is
faster, see |expr-option-function|.
The expression must return the number of spaces worth of indent. It
can return "-1" to keep the current indent (this means 'autoindent' is
used for the indent).
@ -7470,9 +7482,11 @@ A jump table for the options with a short description can be found at |Q_op|.
The file is used for all languages.
expr:{expr} Evaluate expression {expr}. Use a function to avoid
trouble with spaces. |v:val| holds the badly spelled
word. The expression must evaluate to a List of
Lists, each with a suggestion and a score.
trouble with spaces. Best is to call a function
without arguments, see |expr-option-function|.
|v:val| holds the badly spelled word. The expression
must evaluate to a List of Lists, each with a
suggestion and a score.
Example:
[['the', 33], ['that', 44]] ~
Set 'verbose' and use |z=| to see the scores that the