From e84861d510af63969a7ca09e4248426faf2dd345 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 12 Sep 2014 19:40:04 +0200 Subject: Remove unecesarry array operations. --- app/helpers/diff_helper.rb | 18 +++++++++--------- app/views/projects/diffs/_parallel_view.html.haml | 12 ++++++------ .../notes/_diff_notes_with_reply_parallel.html.haml | 3 +-- 3 files changed, 16 insertions(+), 17 deletions(-) (limited to 'app') diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 8332b86d485..c2ce6ed0fe4 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -36,7 +36,10 @@ module DiffHelper # 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| @@ -54,23 +57,20 @@ module DiffHelper next_line = next_line.text end - line = [type, line_old, full_line, line_code, next_line_code, next_type, line_new] - if type == 'match' || type.nil? # 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) elsif type == 'old' if next_type == 'new' # 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) skip_next = true elsif next_type == 'old' || next_type.nil? # Left side has text removed, right side doesn't have any change - line.pop # remove the newline - line.push(nil) # no line number on the right panel - line.push(" ") # empty line on the right panel + # No next line code, no new line number, no new line text + line = [type, line_old, full_line, line_code, next_type, nil, " ", nil] lines.push(line) end elsif type == 'new' @@ -80,7 +80,7 @@ module DiffHelper next else # 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) end end diff --git a/app/views/projects/diffs/_parallel_view.html.haml b/app/views/projects/diffs/_parallel_view.html.haml index 8abbba5b46d..3014e16bc7a 100644 --- a/app/views/projects/diffs/_parallel_view.html.haml +++ b/app/views/projects/diffs/_parallel_view.html.haml @@ -6,10 +6,10 @@ - line_number_left = line[1] - line_content_left = line[2] - line_code = line[3] - - line_code_next = line[4] - - type_right = line[5] - - line_number_right = line[6] - - line_content_right = line[7] + - type_right = line[4] + - line_number_right = line[5] + - line_content_right = line[6] + - line_code_right = line[7] %tr.line_holder.parallel - if type_left == 'match' @@ -22,7 +22,7 @@ - if type_right == 'new' - new_line_class = 'new' - - new_line_code = line_code_next + - new_line_code = line_code_right - else - new_line_class = nil - new_line_code = line_code @@ -37,7 +37,7 @@ - else - comments1 = line_comments[line_code] - unless type_left.nil? && type_right.nil? - - comments2 = line_comments[line_code_next] + - comments2 = line_comments[line_code_right] - if comments1.present? || comments2.present? = render "projects/notes/diff_notes_with_reply_parallel", notes1: comments1, notes2: comments2 diff --git a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml index 6fd25d5f7c6..506d1fff008 100644 --- a/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml +++ b/app/views/projects/notes/_diff_notes_with_reply_parallel.html.haml @@ -1,7 +1,6 @@ - note1 = notes1.present? ? notes1.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 - if note1 %td.notes_line -- cgit v1.2.3