Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
c1c8c7b2
Commit
c1c8c7b2
authored
5 years ago
by
ThibG
Committed by
Eugen Rochko
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Minor performance improvements and cleanup in formatter (#10765)
parent
4ab094d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/formatter.rb
+5
-14
5 additions, 14 deletions
app/lib/formatter.rb
with
5 additions
and
14 deletions
app/lib/formatter.rb
+
5
−
14
View file @
c1c8c7b2
...
...
@@ -187,7 +187,7 @@ class Formatter
end
def
rewrite
(
text
,
entities
)
chars
=
text
.
to_s
.
to_char_a
text
=
text
.
to_s
# Sort by start index
entities
=
entities
.
sort_by
do
|
entity
|
...
...
@@ -199,12 +199,12 @@ class Formatter
last_index
=
entities
.
reduce
(
0
)
do
|
index
,
entity
|
indices
=
entity
.
respond_to?
(
:indices
)
?
entity
.
indices
:
entity
[
:indices
]
result
<<
encode
(
chars
[
index
...
indices
.
first
]
.
join
)
result
<<
encode
(
text
[
index
...
indices
.
first
])
result
<<
yield
(
entity
)
indices
.
last
end
result
<<
encode
(
chars
[
last_index
..-
1
]
.
join
)
result
<<
encode
(
text
[
last_index
..-
1
])
result
.
flatten
.
join
end
...
...
@@ -231,23 +231,14 @@ class Formatter
# Note: I couldn't obtain list_slug with @user/list-name format
# for mention so this requires additional check
special
=
Extractor
.
extract_urls_with_indices
(
escaped
,
options
).
map
do
|
extract
|
# exactly one of :url, :hashtag, :screen_name, :cashtag keys is present
key
=
(
extract
.
keys
&
[
:url
,
:hashtag
,
:screen_name
,
:cashtag
]).
first
new_indices
=
[
old_to_new_index
.
find_index
(
extract
[
:indices
].
first
),
old_to_new_index
.
find_index
(
extract
[
:indices
].
last
),
]
has_prefix_char
=
[
:hashtag
,
:screen_name
,
:cashtag
].
include?
(
key
)
value_indices
=
[
new_indices
.
first
+
(
has_prefix_char
?
1
:
0
),
# account for #, @ or $
new_indices
.
last
-
1
,
]
next
extract
.
merge
(
:
indices
=>
new_indices
,
key
=>
text
[
value
_indices
.
first
..
value
_indices
.
last
]
indices
:
new_indices
,
url:
text
[
new
_indices
.
first
..
new
_indices
.
last
-
1
]
)
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment