mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Improve perf of ActionView::Helpers::TextHelper#excerpt
for large strings.
This commit is contained in:
parent
b39ea7cc36
commit
a40d3debe8
1 changed files with 18 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "active_support/core_ext/string/filters"
|
||||
require "active_support/core_ext/string/access"
|
||||
require "active_support/core_ext/array/extract_options"
|
||||
|
||||
module ActionView
|
||||
|
@ -467,18 +468,25 @@ module ActionView
|
|||
radius = options.fetch(:radius, 100)
|
||||
omission = options.fetch(:omission, "...")
|
||||
|
||||
part = part.split(separator)
|
||||
part.delete("")
|
||||
affix = part.size > radius ? omission : ""
|
||||
|
||||
part = if part_position == :first
|
||||
drop_index = [part.length - radius, 0].max
|
||||
part.drop(drop_index)
|
||||
else
|
||||
part.first(radius)
|
||||
if separator != ""
|
||||
part = part.split(separator)
|
||||
part.delete("")
|
||||
end
|
||||
|
||||
return affix, part.join(separator)
|
||||
affix = part.length > radius ? omission : ""
|
||||
|
||||
part =
|
||||
if part_position == :first
|
||||
part.last(radius)
|
||||
else
|
||||
part.first(radius)
|
||||
end
|
||||
|
||||
if separator != ""
|
||||
part = part.join(separator)
|
||||
end
|
||||
|
||||
return affix, part
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue