[WIP] Refactor plugin system

This supersedes #1335, using funcrefs instead of autocommands to implement providers(it is cleaner and requires less changes).

On November 12, 2014 1:35:34 PM EAT, Thiago de Arruda <notifications@github.com> wrote:
>> +  provider_caller_scope = saved_provider_caller_scope;
>> +  provider_call_nesting--;
>> +  
>> +  return rettv;
>> +}
>> +
>> +bool eval_has_provider(char *name)
>> +{
>> +#define source_provider(name) \
>> +  do_source((uint8_t *)"$VIMRUNTIME/autoload/provider/" name ".vim",
>\
>> +                       false, \
>> +                       false)
>> +
>> +#define check_provider(name)                                        
>     \
>> +  if (has_##name == -1) {                                           
>     \
>> +    has_##name = !!find_func((uint8_t *)"provider#" #name "#Call"); 
>     \
>
>I considered doing this, but decided against it for a couple of
>reasons:
>
>- A "feature" would need a variable number of functions to be
>implemented(clipboard requires 2 and python requires 4). For
>consistency in the feature-checking mechanism I thought it was better
>to encapsulate everything in one function
>- Most providers will simply dispatch `method`/`args` the via
>msgpack-rpc, using one function is cleaner in these cases
>
>> It's faster (find_func uses hash_find instead of depending on #Call()
>to implement an if-elseif-else tree)
>
>I don't think this is faster than comparing a small number of strings.
>Let's not forget that hash functions also have to walk all characters
>and the benefit only stands when the number of possibilities is high.
>Even in a scenario where a provider has a lot of methods, one can
>easily use a vimscript dict to contain the actual implementations keyed
>by method name

You are forgetting about skipping. If you use :if then in any case all branches will be evaluated, just some of them will be skipped (= will not result in actually executing anything, and with most of errors ignored). Translator is too far from release to forget about this, assuming you do care about such minor performance differences.

This problem usually only kicks in if you run thousands of :if's. One of the most problematic for formatvim/2html, resulted in creating code generator in *both* plugins (just I am using generator for everything, 2html only for some bottlenecks).

>
>---
>Reply to this email directly or view it on GitHub:
>https://github.com/neovim/neovim/pull/1454/files#r20211545