BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bd78e6af
Commit
bd78e6af
authored
Aug 30, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use algorithm from Kamil:
Excluding sorting, this is O(n) which should be much faster and much simpler and easier to understand.
parent
031b1623
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
28 deletions
+9
-28
pipeline_duration.rb
lib/gitlab/ci/pipeline_duration.rb
+9
-28
No files found.
lib/gitlab/ci/pipeline_duration.rb
View file @
bd78e6af
...
...
@@ -37,41 +37,22 @@ module Gitlab
if
segments
.
empty?
segments
else
segments
[
1
..-
1
].
inject
([
segments
.
first
])
do
|
current
,
targe
t
|
left
,
result
=
insert_segment
(
current
,
targe
t
)
segments
.
drop
(
1
).
inject
([
segments
.
first
])
do
|
result
,
curren
t
|
merged
=
try_merge_segment
(
result
.
last
,
curren
t
)
if
left
# left is the latest one
result
<<
left
else
if
merged
result
[
-
1
]
=
merged
result
else
result
<<
current
end
end
end
end
def
insert_segment
(
segments
,
init
)
segments
.
inject
([
init
,
[]])
do
|
target_result
,
member
|
target
,
result
=
target_result
if
target
.
nil?
# done
result
<<
member
[
nil
,
result
]
elsif
merged
=
try_merge_segment
(
target
,
member
)
# overlapped
[
merged
,
result
]
# merge and keep finding the hole
elsif
target
.
last
<
member
.
first
# found the hole
result
<<
target
<<
member
[
nil
,
result
]
else
result
<<
member
target_result
end
end
end
def
try_merge_segment
(
target
,
member
)
if
target
.
first
<=
member
.
last
&&
target
.
last
>=
member
.
first
Segment
.
new
([
target
.
first
,
member
.
first
].
min
,
[
target
.
last
,
member
.
last
].
max
)
def
try_merge_segment
(
previous
,
current
)
if
current
.
first
<=
previous
.
last
Segment
.
new
(
previous
.
first
,
[
previous
.
last
,
current
.
last
].
max
)
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