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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
8c1b07e0
Commit
8c1b07e0
authored
May 17, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize reverse_line
parent
6be609dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
+13
-12
lib/gitlab/ci/trace/stream.rb
lib/gitlab/ci/trace/stream.rb
+13
-12
No files found.
lib/gitlab/ci/trace/stream.rb
View file @
8c1b07e0
...
...
@@ -96,30 +96,31 @@ module Gitlab
end
def
reverse_line
pos
=
BUFFER_SIZE
pos
=
0
max
=
stream
.
size
debris
=
''
while
pos
<
max
while
(
read_size
=
calc_read_size
(
pos
,
max
))
>
0
pos
+=
read_size
stream
.
seek
(
-
pos
,
IO
::
SEEK_END
)
stream
.
read
(
BUFFER_SIZE
).
tap
do
|
buf
|
stream
.
read
(
read_size
).
tap
do
|
buf
|
buf
=
buf
+
debris
debris
,
*
lines
=
buf
.
each_line
.
to_a
lines
.
reverse_each
do
|
line
|
yield
(
line
)
end
end
pos
+=
BUFFER_SIZE
end
# Reached the head, read only left
stream
.
seek
(
0
)
last
=
(
max
>
BUFFER_SIZE
)
?
(
max
%
BUFFER_SIZE
)
:
max
stream
.
read
(
last
).
tap
do
|
buf
|
buf
=
buf
+
debris
buf
.
each_line
.
reverse_each
do
|
line
|
yield
(
line
)
end
yield
(
debris
)
if
debris
!=
''
end
def
calc_read_size
(
pos
,
max
)
if
pos
>
max
BUFFER_SIZE
+
(
pos
-
max
)
else
remain
=
max
-
pos
(
remain
>
BUFFER_SIZE
)
?
BUFFER_SIZE
:
remain
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