#summary Removing submatch information in some cases for speedup = Introduction = In a number of cases we only want to know if a regexp matches, it doesn't matter what exactly it matches. E.g. for this statement in a script: if text =~ pattern In this case we should quit the regexp engine with a success result as soon as a match is found. That should be quite a speed improvement compared to an engine that figures out exactly what is matched. = How to get it done = I plan to add two flags in addition to the second parameter of vim_regcomp(). namely, {{{ #define RE_SUB0 8 /* need no submatch info */ #define RE_SUB1 16 /* need 1 submatch info */ }}} then the caller can set it accordingly. This requires the caller explicitly tell how many submatch will be used. If neither is set then everything go as before. = Scenarios = A list of files showing where we could set submatch information for speedup. ==buffer.c== * in buflist_findpat(), _before_: {{{ prog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ prog = vim_regcomp(p, (p_magic ? RE_MAGIC : 0) + RE_SUB0); }}} * in ExpandBufnames(), _before_: {{{ prog = vim_regcomp(patc + attempt * 11, RE_MAGIC); }}} {{{ prog = vim_regcomp(patc + attempt * 11, RE_MAGIC + RE_SUB0); }}} ==edit.c== *ins_compl_files()* uses the submatch 0, the whole match string. Since it is the only place where match takes place we can safely tell the two vim_regcomp() calls in edit.c that we just want one submatch info. _before_: {{{ regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ regmatch.regprog = vim_regcomp(ptr, RE_MAGIC | RE_SUB1); regmatch.regprog = vim_regcomp(pat, (p_magic ? RE_MAGIC : 0) | RE_SUB1); }}} ==eval.c== * in eval4(), _before_: {{{ regmatch.regprog = vim_regcomp(s2, RE_MAGIC + RE_STRING); }}} _after_: {{{ regmatch.regprog = vim_regcomp(s2, RE_MAGIC + RE_STRING + RE_SUB0); }}} * in find_some_match(), no change. * in f_split(), _before_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); }}} _after_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_SUB1); }}} * in ex_function(), _before_: {{{ regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC); }}} _after_: {{{ regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC + RE_SUB0); }}} * in do_string_sub(), _before_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); }}} _after_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_SUB1); }}} ==ex_cmds.c== * in ex_sort(), _before_: {{{ regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC + RE_SUB1); }}} _after_: {{{ regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC + RE_SUB1); }}} ==ex_cmds2.c== * in ex_breakadd(), _before_: {{{ bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); }}} _after_: {{{ bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING + RE_SUB0); }}} * in do_arglist(), _before_: {{{ regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ regmatch.regprog = vim_regcomp(p, (p_magic ? RE_MAGIC : 0)|RE_SUB0); }}} * in ex_open(), _before_: {{{ regmatch.regprog = vim_regcomp(eap->arg, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ regmatch.regprog = vim_regcomp(eap->arg, (p_magic ? RE_MAGIC : 0)|RE_SUB0); }}} * in ex_match(), *FIXME* No change here because I don't know where is the regexec(). ==ex_getln.c== * in ExpandFromContext(), _before_: {{{ regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ regmatch.regprog = vim_regcomp(pat, (p_magic ? RE_MAGIC : 0)|RE_SUB0); }}} * in del_history_entry(), _before_: {{{ regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING) }}} _after_: {{{ regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING + RE_SUB0) }}} ==fileio.c== In match_file_pat(), no submatch info needed. So all three vim_regcomp() are added flag RE_SUB0. ==gui.c== * in gui_do_findrepl(), _before_: {{{ regmatch.regprog = vim_regcomp(ga.ga_data, RE_MAGIC + RE_STRING); }}} _after_: {{{ regmatch.regprog = vim_regcomp(ga.ga_data, RE_MAGIC + RE_STRING + RE_SUB1); }}} ==misc1.c== * in get_number_indent(), _before_: {{{ regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); }}} _after_: {{{ regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC + RE_SUB1); }}} * in dos_expandpath(), _before_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC); }}} _after_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_SUB0); }}} * in unix_expandpath(), _before_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC); }}} _after_: {{{ regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_SUB0); }}} ==option.c== * in check_clipboard_option(), _before_: {{{ new_exclude_prog = vim_regcomp(p, RE_MAGIC); }}} _after_: {{{ new_exclude_prog = vim_regcomp(p, RE_MAGIC + RE_SUB0); }}} * in compile_cap_prog(), _before_: {{{ buf->b_cap_prog = vim_regcomp(re, RE_MAGIC); }}} _after_: {{{ buf->b_cap_prog = vim_regcomp(re, RE_MAGIC + RE_SUB0); }}} ==tags.c== * in prepare_pats(), _before_: {{{ pats->regmatch.regprog = vim_regcomp(pats->pat, p_magic ? RE_MAGIC : 0); }}} _after_: {{{ pats->regmatch.regprog = vim_regcomp(pats->pat, (p_magic ? RE_MAGIC : 0) + RE_SUB1); }}}