[前][次][番号順一覧][スレッド一覧]

ruby-changes:70148

From: YO4 <ko1@a...>
Date: Fri, 10 Dec 2021 22:18:36 +0900 (JST)
Subject: [ruby-changes:70148] 3a2ae5bb19 (master): [ruby/reline] unleash real pasting speed

https://git.ruby-lang.org/ruby.git/commit/?id=3a2ae5bb19

From 3a2ae5bb19a653ac131136c6bf9a7550f64804f6 Mon Sep 17 00:00:00 2001
From: YO4 <ysno@a...>
Date: Thu, 9 Dec 2021 22:36:18 +0900
Subject: [ruby/reline] unleash real pasting speed

2700msec -> 410msec

read 80 console inputs at once

https://github.com/ruby/reline/commit/eb3ef7af98
---
 lib/reline/windows.rb | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index 950d0cf0ca3..32d93a1ca92 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -262,23 +262,27 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L262
         next
       end
       next if @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) == 0 or num_of_events.unpack1('L') == 0
-      input_record = 0.chr * 18
+      input_records = 0.chr * 20 * 80
       read_event = 0.chr * 4
-      if @@ReadConsoleInputW.(@@hConsoleInputHandle, input_record, 1, read_event) != 0
-        event = input_record[0, 2].unpack1('s*')
-        case event
-        when WINDOW_BUFFER_SIZE_EVENT
-          @@winch_handler.()
-        when KEY_EVENT
-          key_down = input_record[4, 4].unpack1('l*')
-          repeat_count = input_record[8, 2].unpack1('s*')
-          virtual_key_code = input_record[10, 2].unpack1('s*')
-          virtual_scan_code = input_record[12, 2].unpack1('s*')
-          char_code = input_record[14, 2].unpack1('S*')
-          control_key_state = input_record[16, 2].unpack1('S*')
-          is_key_down = key_down.zero? ? false : true
-          if is_key_down
-            process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
+      if @@ReadConsoleInputW.(@@hConsoleInputHandle, input_records, 80, read_event) != 0
+        read_events = read_event.unpack1('L')
+        0.upto(read_events) do |idx|
+          input_record = input_records[idx * 20, 20]
+          event = input_record[0, 2].unpack1('s*')
+          case event
+          when WINDOW_BUFFER_SIZE_EVENT
+            @@winch_handler.()
+          when KEY_EVENT
+            key_down = input_record[4, 4].unpack1('l*')
+            repeat_count = input_record[8, 2].unpack1('s*')
+            virtual_key_code = input_record[10, 2].unpack1('s*')
+            virtual_scan_code = input_record[12, 2].unpack1('s*')
+            char_code = input_record[14, 2].unpack1('S*')
+            control_key_state = input_record[16, 2].unpack1('S*')
+            is_key_down = key_down.zero? ? false : true
+            if is_key_down
+              process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
+            end
           end
         end
       end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]