Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Match to the end of string when using (S) flag
- X-seq: zsh-users 22064
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Match to the end of string when using (S) flag
- Date: Tue, 01 Nov 2016 11:29:35 -0700
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=GFz/UHbcDVOpiqn RlzxtAKhPdRM=; b=SFczRzmYxtFXPwcq3PuRYaW8e4Mpu7kkkwMuYiXVTxKhnml dETcNBjlLIpiv2PTpIw3YS6S1xt3AcH0vjSEej5uSoOBwyajj1u9KRQAcqeeB6XW /N0F7VnhHtrCjpWLc1SxIshYs1k+RWHqu5WsmijbIA/XblAaINVI1WIMfiAs=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=GFz/UHbcDVOpiqnRlzxtAKhPdRM=; b=XULbDBdivaPDH1Z8XPzq xej+sDlL6NFA4taqWJJoDkpAFAD8nPmk5IRSeSsqo5a/Io499Bjm6kbB9a4oAGAQ JqRDTlikopZ/c2LS96PgxW2RSF3AfILUMmFPMmZLCOVBEamPRzBAnMH+DMZJU1dw r3P+GEvhrBoIKvNQccVQ6iU=
- In-reply-to: <1478017673.3085741.773974873.7C58DD0B@webmail.messagingengine.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1478010333.3056500.773811025.1AAA4FEC@webmail.messagingengine.com> <1478017673.3085741.773974873.7C58DD0B@webmail.messagingengine.com>
A miracle optimization – via mathematical function!
__hsmw_region_highlight_data=( )
: "${text//(#mi)(${~colsearch_pattern})/$(( append(MBEGIN,MEND) ))}"
region_highlight+=( $__hsmw_region_highlight_data )
shappend() {
__hsmw_region_highlight_data+=( "$(( offset + $1 - 1 )) $((
offset + $2 )) ${__hsmw_hl_color}" )
}
functions -M append 2 2 shappend
This gives total time (time of anonymous function wrapping first three
lines) for a complex – three-word A|B|C – input pattern: 44 ms (17 ms in
shappend).
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).
Time of original one-liner without math-function call: 502 ms.
--
Sebastian Gniazdowski
psprint@xxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author