Commit e84861d5 authored by Marin Jankovski's avatar Marin Jankovski

Remove unecesarry array operations.

parent 5564fe31
...@@ -36,7 +36,10 @@ module DiffHelper ...@@ -36,7 +36,10 @@ module DiffHelper
# Building array of lines # Building array of lines
# #
# [left_type, left_line_number, left_line_content, line_code, right_line_type, right_line_number, right_line_content] # [
# left_type, left_line_number, left_line_content, left_line_code,
# right_line_type, right_line_number, right_line_content, right_line_code
# ]
# #
diff_file.diff_lines.each do |line| diff_file.diff_lines.each do |line|
...@@ -54,23 +57,20 @@ module DiffHelper ...@@ -54,23 +57,20 @@ module DiffHelper
next_line = next_line.text next_line = next_line.text
end end
line = [type, line_old, full_line, line_code, next_line_code, next_type, line_new]
if type == 'match' || type.nil? if type == 'match' || type.nil?
# line in the right panel is the same as in the left one # line in the right panel is the same as in the left one
line = [type, line_old, full_line, line_code, line_code, type, line_new, full_line] line = [type, line_old, full_line, line_code, type, line_new, full_line, line_code]
lines.push(line) lines.push(line)
elsif type == 'old' elsif type == 'old'
if next_type == 'new' if next_type == 'new'
# Left side has text removed, right side has text added # Left side has text removed, right side has text added
line.push(next_line) line = [type, line_old, full_line, line_code, next_type, line_new, next_line, next_line_code]
lines.push(line) lines.push(line)
skip_next = true skip_next = true
elsif next_type == 'old' || next_type.nil? elsif next_type == 'old' || next_type.nil?
# Left side has text removed, right side doesn't have any change # Left side has text removed, right side doesn't have any change
line.pop # remove the newline # No next line code, no new line number, no new line text
line.push(nil) # no line number on the right panel line = [type, line_old, full_line, line_code, next_type, nil, " ", nil]
line.push(" ") # empty line on the right panel
lines.push(line) lines.push(line)
end end
elsif type == 'new' elsif type == 'new'
...@@ -80,7 +80,7 @@ module DiffHelper ...@@ -80,7 +80,7 @@ module DiffHelper
next next
else else
# Change is only on the right side, left side has no change # Change is only on the right side, left side has no change
line = [nil, nil, " ", line_code, line_code, type, line_new, full_line] line = [nil, nil, " ", line_code, type, line_new, full_line, line_code]
lines.push(line) lines.push(line)
end end
end end
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
- line_number_left = line[1] - line_number_left = line[1]
- line_content_left = line[2] - line_content_left = line[2]
- line_code = line[3] - line_code = line[3]
- line_code_next = line[4] - type_right = line[4]
- type_right = line[5] - line_number_right = line[5]
- line_number_right = line[6] - line_content_right = line[6]
- line_content_right = line[7] - line_code_right = line[7]
%tr.line_holder.parallel %tr.line_holder.parallel
- if type_left == 'match' - if type_left == 'match'
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
- if type_right == 'new' - if type_right == 'new'
- new_line_class = 'new' - new_line_class = 'new'
- new_line_code = line_code_next - new_line_code = line_code_right
- else - else
- new_line_class = nil - new_line_class = nil
- new_line_code = line_code - new_line_code = line_code
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
- else - else
- comments1 = line_comments[line_code] - comments1 = line_comments[line_code]
- unless type_left.nil? && type_right.nil? - unless type_left.nil? && type_right.nil?
- comments2 = line_comments[line_code_next] - comments2 = line_comments[line_code_right]
- if comments1.present? || comments2.present? - if comments1.present? || comments2.present?
= render "projects/notes/diff_notes_with_reply_parallel", notes1: comments1, notes2: comments2 = render "projects/notes/diff_notes_with_reply_parallel", notes1: comments1, notes2: comments2
......
- note1 = notes1.present? ? notes1.first : nil - note1 = notes1.present? ? notes1.first : nil
- note2 = notes2.present? ? notes2.first : nil - note2 = notes2.present? ? notes2.first : nil
-# Check if line want not changed since comment was left
/- if !defined?(line) || line == note.diff_line
%tr.notes_holder %tr.notes_holder
- if note1 - if note1
%td.notes_line %td.notes_line
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment