1
0
Fork 0
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:
Eugene Kenny 2020-12-27 20:03:46 +00:00 committed by GitHub
commit f3071970c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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