[ruby/irb] Remove bignum check from save_history

(https://github.com/ruby/irb/pull/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.

https://github.com/ruby/irb/commit/5151467e6a
This commit is contained in:
tomoya ishida 2024-10-13 22:00:17 +09:00 committed by git
parent 6393d2950d
commit cf8388f76c

View File

@ -5,10 +5,7 @@ module IRB
class << self class << self
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>. # Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
def save_history def save_history
num = IRB.conf[:SAVE_HISTORY].to_i IRB.conf[:SAVE_HISTORY].to_i
# Bignums cause RangeErrors when slicing arrays.
# Treat such values as 'infinite'.
(num > save_history_max) ? -1 : num
end end
def save_history? def save_history?
@ -27,13 +24,6 @@ module IRB
IRB.rc_file("_history") IRB.rc_file("_history")
end end
end end
private
def save_history_max
# Max fixnum (32-bit) that can be used without getting RangeError.
2**30 - 1
end
end end
end end
@ -90,7 +80,8 @@ module IRB
hist = history.map { |l| l.scrub.split("\n").join("\\\n") } hist = history.map { |l| l.scrub.split("\n").join("\\\n") }
unless append_history || History.infinite? unless append_history || History.infinite?
hist = hist.last(History.save_history) # Check size before slicing because array.last(huge_number) raises RangeError.
hist = hist.last(History.save_history) if hist.size > History.save_history
end end
f.puts(hist) f.puts(hist)