Uncouple the "impossible" branch of changed colors.

This improves startup speed and next-prompt speed by giving them
flatter logic paths.  At the cost of needing to maintain the basic
idea in two places.
This commit is contained in:
2026-06-24 02:45:34 -04:00
parent 429f45d1e8
commit 10992c1424
+17 -13
View File
@@ -36,25 +36,29 @@ set prompt_segment_kinds=( \
prompt \
)
foreach kind ( ${prompt_segment_kinds} )
eval 'echo $?curr_'"${kind}"'_color' >& /dev/null
_debug "Eval of ${kind}"
if( $? == 0 ) then
eval "set curr_${kind}_color=impossible"
endif
eval 'set __new_this_color="${'"${kind}"'_color}"'
eval 'set __curr_this_color="${curr_'"${kind}"'_color}"'
if( "${__new_this_color}" != ${__curr_this_color} ) then
# The algorithm is duplicated with less branching to make startup a bit faster.
if ( ! $?cshenv_prompt_first_cache ) then
foreach kind ( ${prompt_segment_kinds} )
eval 'set __new_this_color="${'"${kind}"'_color}"'
eval 'set curr_'"${kind}"'_color="'${__new_this_color}'"'
set __this_color_seq="%{[`__build_sgr_code no-csi reset ${__new_this_color}`m%}"
eval 'set '"${kind}"'_color_seq="'"${__this_color_seq}"'"'
endif
end
end
set cshenv_prompt_first_cache=1
else
foreach kind ( ${prompt_segment_kinds} )
eval 'set __new_this_color="${'"${kind}"'_color}"'
eval 'set __curr_this_color="${curr_'"${kind}"'_color}"'
if( "${__new_this_color}" == "${__curr_this_color}" ) continue
eval 'set curr_'"${kind}"'_color="'${__new_this_color}'"'
set __this_color_seq="%{[`__build_sgr_code no-csi reset ${__new_this_color}`m%}"
eval 'set '"${kind}"'_color_seq="'"${__this_color_seq}"'"'
end
endif
_debug "Done with color cacheing loop"
_debug "Dynamic color loading processed..."