gpt4 book ai didi

ruby - 将文本粘贴到 IRB 中非常慢。阅读线问题?

转载 作者:数据小太阳 更新时间:2023-10-29 06:39:42 27 4
gpt4 key购买 nike

当我将以下文本粘贴到在 ruby​​-enterprise-2011.03 下运行的 IRB 或 PRY 时,需要 13 秒。

# Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

在同一台计算机上运行 irb 和其他 ruby​​ 安装时,粘贴并不慢。

  jruby-1.5.6
jruby-1.6.3
ruby-1.8.6-p420
ruby-1.8.7-p352
ruby-1.9.1-p431
ruby-1.9.2-p290
ruby-1.9.3-preview1
or Mac OS X's default system install of 1.8.7-p249

这个问题与Rails console running incredibly slowly when editing text有关,但我没有使用 rvm,并且在编写、编辑或删除文本时没有缓慢;只有粘贴很慢。 @fl00r 的建议有效,但这不是永久性的解决方法。

另外,如果粘贴的文本中有硬换行,只有最后一行比较慢。比如粘贴下面的文字只需要1.5秒左右

# Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
# sed do eiusmod tempor incididunt ut labore et dolore magna
# aliqua.

我注意到 REE 加载了 libreadline 的副本,而其他 ruby​​ 安装均未加载。有没有办法配置和编译 REE 以忽略来自 MacPorts 的 libreadline 文件?

require 'readline'
puts `lsof -p #{$$} | grep -i readline | awk '{print $9}'`
puts

我在几个 ruby​​ 安装上运行了上面的脚本。只有底部的 2 个安装(REE 安装)包含额外的 libreadline。

=== ruby-1.8.6-p36 ======================
/opt/ruby-1.8.6-p36/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle

=== ruby-1.8.6-p420 ======================
/opt/ruby-1.8.6-p420/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle

=== ruby-1.8.7-p352 ======================
/opt/ruby-1.8.7-p352/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle

=== ruby-1.9.1-p431 ======================
/opt/ruby-1.9.1-p431/lib/ruby/1.9.1/i386-darwin11.0.1/readline.bundle

=== ruby-1.9.2-p290 ======================
/opt/ruby-1.9.2-p290/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle

=== ruby-1.9.3-preview1 ==================
/opt/ruby-1.9.3-preview1/lib/ruby/1.9.1/x86_64-darwin11.0.1/readline.bundle

=== ruby-enterprise-1.8.7-2011.03 ========
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/i686-darwin11.0.1/readline.bundle
/opt/local/lib/libreadline.6.2.dylib

=== ruby-enterprise-1.8.7-2012.01 ========
/opt/ruby-enterprise-1.8.7-2012.01/lib/ruby/1.8/i686-darwin11.2.0/readline.bundle
/opt/local/lib/libreadline.6.2.dylib

最佳答案

这是 Readline 和 UTF-8 终端的问题。我没有花时间追查真正的问题出在哪里,但是,如果您将 $LANG 设置为其他值,问题就会消失。

这不是永久性的解决方案。

另一个快速解决方法是在粘贴文本后键入一个额外的字符。

如果您重新编译 ruby​​ 不使用 Readline,您也可以返回使用 OSX 的 editline 库。可悲的是,这带来了它自己的问题,例如 ruby​​s readline 的 editline 兼容性会阻塞线程。

我还应该指出,不仅仅是 ruby​​ 遇到了这个问题,自 Snow Leopard 以来,我在 OSX 上的其他 readline 实现中也看到过这个问题。

关于ruby - 将文本粘贴到 IRB 中非常慢。阅读线问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7296169/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com