From 942025be9b654a5908770ae3adcfd25aa5cfb2b1 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 25 Jan 2020 19:11:58 -0500 Subject: [PATCH] microoptimization to avoid the more expensive regex --- markitzero.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/markitzero.go b/markitzero.go index 8f76b4f..c524794 100644 --- a/markitzero.go +++ b/markitzero.go @@ -75,10 +75,14 @@ func markitzero(s string) string { s = string(buf) // mark it zero - s = re_link.ReplaceAllStringFunc(s, linkreplacer) + if strings.Contains(s, "http") { + s = re_link.ReplaceAllStringFunc(s, linkreplacer) + } s = re_zerolink.ReplaceAllString(s, `$1`) - s = re_bolder.ReplaceAllString(s, "$1$2$3") - s = re_italicer.ReplaceAllString(s, "$1$2$3") + if strings.Contains(s, "*") { + s = re_bolder.ReplaceAllString(s, "$1$2$3") + s = re_italicer.ReplaceAllString(s, "$1$2$3") + } s = re_quoter.ReplaceAllString(s, "
$1
$3

") s = re_reciter.ReplaceAllString(s, "$1$2$3") s = strings.Replace(s, "\n---\n", "


", -1)