Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Match to the end of string when using (S) flag



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.



Messages sorted by: Reverse Date, Date, Thread, Author