Skip to content

Commit

Permalink
Merge branch 'even-faster-search' into 'master'
Browse files Browse the repository at this point in the history
Avoid copy of strings in memory for parsing git grep result

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

See merge request !967
  • Loading branch information
dzaporozhets committed Jul 17, 2015
2 parents 53d9f78 + bbd3d2c commit 67fb9ef
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,20 +449,19 @@ def parse_search_result(result)
filename = nil
startline = 0

lines = result.lines
lines.each_with_index do |line, index|
result.each_line.each_with_index do |line, index|
if line =~ /^.*:.*:\d+:/
ref, filename, startline = line.split(':')
startline = startline.to_i - index
break
end
end

data = lines.map do |line|
line.sub(ref, '').sub(filename, '').sub(/^:-\d+-/, '').sub(/^::\d+:/, '')
end
data = ""

data = data.join("")
result.each_line do |line|
data << line.sub(ref, '').sub(filename, '').sub(/^:-\d+-/, '').sub(/^::\d+:/, '')
end

OpenStruct.new(
filename: filename,
Expand Down

0 comments on commit 67fb9ef

Please sign in to comment.