mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #39979 from tgxworld/speed_up_text_helper_excerpt
Improve perf of `ActionView::Helpers::TextHelper#excerpt` for large strings.
This commit is contained in:
commit
f3071970c2
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"
|
||||
require "action_view/helpers/sanitize_helper"
|
||||
require "action_view/helpers/tag_helper"
|
||||
|
@ -470,18 +471,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