1
0
Fork 0
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:
Guo Xiang Tan 2020-08-04 16:59:40 +08:00 committed by Alan Guo Xiang Tan
parent b39ea7cc36
commit a40d3debe8
No known key found for this signature in database
GPG key ID: 3F656E28E3AADEF1

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