Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
16168b5b
Commit
16168b5b
authored
May 23, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the iterator inside DiffCollection only once
parent
fcdc4279
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
18 deletions
+21
-18
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+21
-18
No files found.
lib/gitlab/git/diff_collection.rb
View file @
16168b5b
...
...
@@ -19,22 +19,19 @@ module Gitlab
@line_count
=
0
@byte_count
=
0
@overflow
=
false
@empty
=
true
@array
=
Array
.
new
end
def
each
(
&
block
)
if
@populated
# @iterator.each is slower than just iterating the array in place
@array
.
each
(
&
block
)
else
Gitlab
::
GitalyClient
.
migrate
(
:commit_raw_diffs
)
do
each_patch
(
&
block
)
end
end
end
def
empty?
!
@iterator
.
any?
any?
# Make sure the iterator has been exercised
@empty
end
def
overflow?
...
...
@@ -60,7 +57,6 @@ module Gitlab
collection
=
each_with_index
do
|
element
,
i
|
@array
[
i
]
=
yield
(
element
)
end
@populated
=
true
collection
end
...
...
@@ -70,7 +66,6 @@ module Gitlab
return
if
@populated
each
{
nil
}
# force a loop through all diffs
@populated
=
true
nil
end
...
...
@@ -79,15 +74,17 @@ module Gitlab
end
def
each_patch
@iterator
.
each_with_index
do
|
raw
,
i
|
# First yield cached Diff instances from @array
if
@array
[
i
]
yield
@array
[
i
]
next
i
=
0
@array
.
each
do
|
diff
|
yield
diff
i
+=
1
end
# We have exhausted @array, time to create new Diff instances or stop.
break
if
@overflow
return
if
@overflow
return
if
@iterator
.
nil?
@iterator
.
each
do
|
raw
|
@empty
=
false
if
!
@all_diffs
&&
i
>=
@max_files
@overflow
=
true
...
...
@@ -113,7 +110,13 @@ module Gitlab
end
yield
@array
[
i
]
=
diff
i
+=
1
end
@populated
=
true
# Allow iterator to be garbage-collected. It cannot be reused anyway.
@iterator
=
nil
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment