Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_rl_adjust_point: performance fix with large point
_rl_adjust_point() takes a long time when inserting text. If point argument is a large value, performance is poor. In this case, counting byte size from tail of the string will improve performance. Resetting encoding instead of String#dup will give a small improvement. Tested-by: Mark Somerville <mark@scottishclimbs.com> [F16, MRI 1.8.7, MRI 1.9.3] Signed-off-by: Mark Somerville <mark@scottishclimbs.com>
- Loading branch information
Showing
3 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib/" | ||
require 'rbreadline' | ||
require 'benchmark' | ||
|
||
N = 100_000 | ||
|
||
Benchmark.bmbm do |x| | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("a", 0) } | ||
end | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("a", 1) } | ||
end | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("aaaaaaaaaaaaaaaaaaaaa", 0) } | ||
end | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("aaaaaaaaaaaaaaaaaaaaa", 40) } | ||
end | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0) } | ||
end | ||
x.report do | ||
N.times { RbReadline._rl_adjust_point("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 40) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters