Skip to content
Myr

Remove unnecessary regexp matches

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This change does have positive effect on startup time of fzf when many number of options are provided. time fzf --query=____ --filter=____ --delimiter=q --prompt=________ \ --nth=1,2,3,4 --with-nth=1,2,3,4 --toggle-sort=ctrl-r \ --expect=ctrl-x --tiebreak=index --color=light --bind=ctrl-t:accept \ --history=/tmp/xxx --history-max=1000 --help 0m0.013s -> 0m0.008s

authored by Junegunn Choi · committed by Junegunn Choi · parent 77bab51 · Browse files · 1 file+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:src/options.go+10 added-10 removed
172 unmodified lines
173 os.Stderr.WriteString(msg + "\n")174 help(1)175}176177func optString(arg string, prefix string) (bool, string) {178 rx, _ := regexp.Compile(fmt.Sprintf("^(?:%s)(.*)$", prefix))179 matches := rx.FindStringSubmatch(arg)180 if len(matches) > 1 {181 return true, matches[1]177func optString(arg string, prefixes ...string) (bool, string) {178 for _, prefix := range prefixes {179 if strings.HasPrefix(arg, prefix) {180 return true, arg[len(prefix):]181 }182 }183 return false, ""184}185
418 unmodified lines
604 setHistoryMax(nextInt(allArgs, &i, "history max size required"))605 case "--version":606 opts.Version = true607 default:608 if match, value := optString(arg, "-q|--query="); match {608 if match, value := optString(arg, "-q", "--query="); match {609 opts.Query = value610 } else if match, value := optString(arg, "-f|--filter="); match {610 } else if match, value := optString(arg, "-f", "--filter="); match {611 opts.Filter = &value612 } else if match, value := optString(arg, "-d|--delimiter="); match {612 } else if match, value := optString(arg, "-d", "--delimiter="); match {613 opts.Delimiter = delimiterRegexp(value)614 } else if match, value := optString(arg, "--prompt="); match {615 opts.Prompt = value616 } else if match, value := optString(arg, "-n|--nth="); match {616 } else if match, value := optString(arg, "-n", "--nth="); match {617 opts.Nth = splitNth(value)618 } else if match, value := optString(arg, "--with-nth="); match {619 opts.WithNth = splitNth(value)620 } else if match, _ := optString(arg, "-s|--sort="); match {620 } else if match, _ := optString(arg, "-s", "--sort="); match {621 opts.Sort = 1 // Don't care622 } else if match, value := optString(arg, "--toggle-sort="); match {623 keymap = checkToggleSort(keymap, value)624 opts.ToggleSort = true
57 unmodified lines