Skip to content

Commit 2839e5e

Browse files
committed
performance: let's do no add compactValue attr if it is the same as regular value
1 parent 84e93e3 commit 2839e5e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ def print_variable(name, value, kind)
171171
end
172172
end
173173
value_str = handle_binary_data(value_str)
174-
compact_value_str = build_compact_name(value_str, value)
175174
escaped_value_str = CGI.escapeHTML(value_str)
176-
print("<variable name=\"%s\" compactValue=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
177-
CGI.escapeHTML(name), CGI.escapeHTML(compact_value_str), kind, escaped_value_str, value.class,
175+
print("<variable name=\"%s\" %s kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">",
176+
CGI.escapeHTML(name), build_compact_value_attr(value), kind, escaped_value_str, value.class,
178177
has_children, value.respond_to?(:object_id) ? value.object_id : value.id)
179178
print("<value><![CDATA[%s]]></value>", escaped_value_str)
180179
print('</variable>')
@@ -342,10 +341,10 @@ def current_thread_attr(context)
342341
end
343342
end
344343

345-
def build_compact_name(value_str, value)
344+
def build_compact_name(value)
346345
return compact_array_str(value) if value.is_a?(Array)
347346
return compact_hash_str(value) if value.is_a?(Hash)
348-
value_str
347+
nil
349348
end
350349

351350
def compact_array_str(value)
@@ -363,6 +362,11 @@ def compact_hash_str(value)
363362
"{" + compact + (slice.size != value.size ? ", ..." : "") + "}"
364363
end
365364

365+
def build_compact_value_attr(value)
366+
compact_value_str = build_compact_name(value)
367+
compact_value_str.nil? ? '' : "compactValue=\"#{CGI.escapeHTML(compact_value_str)}\""
368+
end
369+
366370
instance_methods.each do |m|
367371
if m.to_s.index('print_') == 0
368372
protect m

0 commit comments

Comments
 (0)