ruby-changes:63937
From: aycabta <ko1@a...>
Date: Sat, 5 Dec 2020 03:09:41 +0900 (JST)
Subject: [ruby-changes:63937] 2910684c45 (master): [ruby/reline] Cache dynamic prompt for 0.5sec
https://git.ruby-lang.org/ruby.git/commit/?id=2910684c45 From 2910684c45399eed4dcebda72637a37858b74a62 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 21 Nov 2020 00:30:11 +0900 Subject: [ruby/reline] Cache dynamic prompt for 0.5sec https://github.com/ruby/reline/commit/06b89d0e61 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index fc7e576..1328668 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -78,7 +78,12 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L78 end return [prompt, calculate_width(prompt, true), [prompt] * buffer.size] if simplified_rendering? if @prompt_proc - prompt_list = @prompt_proc.(buffer) + if @cached_prompt_list and Time.now.to_f < (@prompt_cache_time + 0.5) + prompt_list = @cached_prompt_list + else + prompt_list = @cached_prompt_list = @prompt_proc.(buffer) + @prompt_cache_time = Time.now.to_f + end prompt_list.map!{ prompt } if @vi_arg or @searching_prompt if @config.show_mode_in_prompt if @config.editing_mode_is?(:vi_command) @@ -191,6 +196,8 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L196 @first_char = true @add_newline_to_end_of_buffer = false @just_cursor_moving = false + @cached_prompt_list = nil + @prompt_cache_time = nil @eof = false @continuous_insertion_buffer = String.new(encoding: @encoding) reset_line -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/