Skip to content

Commit cf8388f

Browse files
tompngmatzbot
authored andcommitted
[ruby/irb] Remove bignum check from save_history
(ruby/irb#1018) IRB need to accept bignum history size, but we don't want explicit bignum checks because threshold of bignum and fixnum depends on platform. ruby/irb@5151467e6a
1 parent 6393d29 commit cf8388f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

lib/irb/history.rb

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ module History
55
class << self
66
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
77
def save_history
8-
num = IRB.conf[:SAVE_HISTORY].to_i
9-
# Bignums cause RangeErrors when slicing arrays.
10-
# Treat such values as 'infinite'.
11-
(num > save_history_max) ? -1 : num
8+
IRB.conf[:SAVE_HISTORY].to_i
129
end
1310

1411
def save_history?
@@ -27,13 +24,6 @@ def history_file
2724
IRB.rc_file("_history")
2825
end
2926
end
30-
31-
private
32-
33-
def save_history_max
34-
# Max fixnum (32-bit) that can be used without getting RangeError.
35-
2**30 - 1
36-
end
3727
end
3828
end
3929

@@ -90,7 +80,8 @@ def save_history
9080
hist = history.map { |l| l.scrub.split("\n").join("\\\n") }
9181

9282
unless append_history || History.infinite?
93-
hist = hist.last(History.save_history)
83+
# Check size before slicing because array.last(huge_number) raises RangeError.
84+
hist = hist.last(History.save_history) if hist.size > History.save_history
9485
end
9586

9687
f.puts(hist)

0 commit comments

Comments
 (0)