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

Re: Slow highlighting (Re: "drop-in replacement" and transpose-words-match)



On 11 February 2016 at 11:43, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
> That said, zsyh could be somewhat optimized if the ":howmany" syntax
> would be utilized.

Could came up with this:
./parse.zsh "zplugin.zsh" > out1.txt 128,78s user 8,61s system 99% cpu
2:17,85 total
./parse.zsh "zplugin.zsh" > out2.txt 74,34s user 8,38s system 99% cpu
1:23,12 total

https://github.com/zsh-users/zsh-syntax-highlighting/pull/272

--- a/highlighters/main/main-highlighter.zsh
+++ b/highlighters/main/main-highlighter.zsh
@@ -125,6 +125,7 @@ _zsh_highlight_main_highlighter()
   typeset -a ZSH_HIGHLIGHT_TOKENS_CONTROL_FLOW
   local -a options_to_set # used in callees
   local buf="$PREBUFFER$BUFFER"
+  integer len="${#buf}"
   region_highlight=()

   if (( path_dirs_was_set )); then
@@ -234,11 +235,13 @@ _zsh_highlight_main_highlighter()
       # indistinguishable from 'echo foo echo bar' (one command with three
       # words for arguments).
       local needle=$'[;\n]'
-      integer offset=${${buf[start_pos+1,-1]}[(i)$needle]}
+      # Len-start_pos drops one character, but it should do it, as start_pos
+      # starts from next, not from "start_pos", character
+      integer offset=${${buf: start_pos: len-start_pos}[(i)$needle]}
       (( start_pos += offset - 1 ))
       (( end_pos = start_pos + $#arg ))
     else
-      ((start_pos+=${#buf[$start_pos+1,-1]}-${#${buf[$start_pos+1,-1]##([[:space:]]|\\[[:space:]])#}}))
+      ((start_pos+=(len-start_pos)-${#${${buf: start_pos:
len-start_pos}##([[:space:]]|\\[[:space:]])#}}))
       ((end_pos=$start_pos+${#arg}))

Best regards,
Sebastian Gniazdowski



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