From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29094 invoked by alias); 1 Nov 2016 21:28:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22066 Received: (qmail 29711 invoked from network); 1 Nov 2016 21:28:43 -0000 X-Qmail-Scanner-Diagnostics: from mail-ua0-f173.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.217.173):SA:0(0.0/5.0):. Processed in 0.575106 secs); 01 Nov 2016 21:28:43 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_PASS,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.173 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=jn5L3kBwAilEZ08mqmuQSjHgf+eAF5MZrSVSaN2OtYY=; b=RFeEmfNUeUQbC1Xc1C/ctnPtlxJ1+eLIjo7b7WtGgiNS4NLUTIaSVAeUeH3ahC9ub0 Oykh9NbEha1Cp29IEHOOZQ2PfvkoxWjI/XC//3zcNr9JHgasjvyo9r2aR2xdu0F1dbF5 Xje+9pLiGpzFsVW6XK387Rg9aYPaL/OTUp3+DK4jFY4Xsr7qSEHZWD6wjXrnWU7cE5qY sZ+PEbvgIKwDLCjcTbqZ9ghDHDEFdENE30swAuHMrKFVbSP/acdHt+fvC6RxSvn4MOQz laQimEONmMFdE1ui7WBvuyFDXcNZQsRMN47vNyrImN+SFL/e0weJ2ZB88+6WMEmpuCQy mI1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=jn5L3kBwAilEZ08mqmuQSjHgf+eAF5MZrSVSaN2OtYY=; b=PM/aTCkBIYObGoGPORcx9Y2YOcvcRspXFyTserK3wi7ioc+5p1yY9PdystZKDsRfSv +SXiSqQwPp5H8kK4IAMcfWTJ4TCBqHNqonr9h0VBk8X+pcFtfudt1s6Qsf9Phu8nqxd4 nd/ZvU12m4sTwH+kKUX63X1iH3YOwgGpLbd/NsX7aW+c1bBJ1hnvz/UnG+q+LtRcbRP/ +sqw0lW1MfqxD+oncyjAL+3lFhGryIC05hXQRG5s6/Yt5IJ13t4oCMhhzXwt08U9mN91 um9RVS0hDglvnkwYvIHehS83lDscV+2g6uNgZpHo9gSStJpKgbSdQ+YdoSk2NSvFwc3i R+sg== X-Gm-Message-State: ABUngvfJeyvBZgsvOq6b/jSh6uXD3qP/mZEXLH/m0MbW7UiViv8uba/4VeFSRuH9wmj4fA== X-Received: by 10.159.39.7 with SMTP id a7mr39240uaa.95.1478035357346; Tue, 01 Nov 2016 14:22:37 -0700 (PDT) From: Bart Schaefer Message-Id: <161101142301.ZM25643@torch.brasslantern.com> Date: Tue, 1 Nov 2016 14:23:01 -0700 In-Reply-To: <1478024975.3113621.774078481.323B1F9E@webmail.messagingengine.com> Comments: In reply to Sebastian Gniazdowski "Re: Match to the end of string when using (S) flag" (Nov 1, 11:29am) References: <1478010333.3056500.773811025.1AAA4FEC@webmail.messagingengine.com> <1478017673.3085741.773974873.7C58DD0B@webmail.messagingengine.com> <1478024975.3113621.774078481.323B1F9E@webmail.messagingengine.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Match to the end of string when using (S) flag MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Nov 1, 11:29am, Sebastian Gniazdowski wrote: } } A miracle optimization - via mathematical function! You can do this with just a counter, you don't need a math function: i=$#region_highlight : ${text//(#mi)(${~colsearch_pattern})/ ${region_highlight[++i]=$((offset + MBEGIN))} ${region_highlight[++i]=$((offset + MEND))} ${region_highlight[++i]=${__hsmw_hl_color}}} } When I do: } : "${(S)text//*(#bi)(${~colsearch_pattern})/$(( } append(mbegin[1],mend[1]) ))}" } } then the time is: 528 ms ! After removing leading star *: 52 ms (18 ms } in shappend). With the leading "*" the algorithm has to check after each character whether the following characters match the sub-pattern in the parens, so it's checking every position multiple times. I have to give you credit for coming up with the idea of using a text replacement in the first place. I had to re-read your first message on this thread about four times before I understood what it meant.