Skip to content

Commit 7e5f7f5

Browse files
viuginick1valich
authored andcommitted
refactoring: move jruby check into exec_with_allocation_method
1 parent f821ffb commit 7e5f7f5

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def print_string(string)
160160
end
161161

162162
def exec_with_allocation_control(value, memory_limit, time_limit, exec_method, return_message_if_overflow)
163+
if (defined?(JRUBY_VERSION) || ENV['DEBUGGER_MEMORY_LIMIT'].to_i <= 0)
164+
return value.send exec_method
165+
end
163166
curr_thread = Thread.current
164167
result = nil
165168
inspect_thread = DebugThread.start {
@@ -217,11 +220,7 @@ def print_variable(name, value, kind)
217220
else
218221
has_children = !value.instance_variables.empty? || !value.class.class_variables.empty?
219222

220-
value_str = if (defined?(JRUBY_VERSION) || ENV['DEBUGGER_MEMORY_LIMIT'].to_i <= 0)
221-
value.to_s || 'nil' rescue "<#to_s method raised exception: #{$!}>"
222-
else
223-
exec_with_allocation_control(value, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, true) || 'nil' rescue "<#to_s method raised exception: #{$!}>"
224-
end
223+
value_str = exec_with_allocation_control(value, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :to_s, true) || 'nil' rescue "<#to_s method raised exception: #{$!}>"
225224

226225
unless value_str.is_a?(String)
227226
value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String."
@@ -448,11 +447,7 @@ def max_compact_name_size
448447
def compact_array_str(value)
449448
slice = value[0..10]
450449

451-
compact = if (defined?(JRUBY_VERSION) || ENV['DEBUGGER_MEMORY_LIMIT'].to_i <= 0)
452-
slice.inspect
453-
else
454-
exec_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :inspect, true)
455-
end
450+
compact = exec_with_allocation_control(slice, ENV['DEBUGGER_MEMORY_LIMIT'].to_i, ENV['INSPECT_TIME_LIMIT'].to_i, :inspect, true)
456451

457452
if compact && value.size != slice.size
458453
compact[0..compact.size-2] + ", ...]"

0 commit comments

Comments
 (0)