mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
move slice_collection optimization to utils
This commit is contained in:
@@ -23,7 +23,7 @@ module Liquid
|
||||
from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
|
||||
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
|
||||
|
||||
collection = Utils.slice_collection_using_each(collection, from, to)
|
||||
collection = Utils.slice_collection(collection, from, to)
|
||||
|
||||
length = collection.length
|
||||
|
||||
|
||||
@@ -75,11 +75,7 @@ module Liquid
|
||||
limit = context[@attributes['limit']]
|
||||
to = limit ? limit.to_i + from : nil
|
||||
|
||||
segment = if (from != 0 || to != nil) && collection.respond_to?(:load_slice)
|
||||
collection.load_slice(from, to)
|
||||
else
|
||||
Utils.slice_collection_using_each(collection, from, to)
|
||||
end
|
||||
segment = Utils.slice_collection(collection, from, to)
|
||||
|
||||
return render_else(context) if segment.empty?
|
||||
|
||||
|
||||
+15
-4
@@ -1,5 +1,20 @@
|
||||
module Liquid
|
||||
module Utils
|
||||
|
||||
def self.slice_collection(collection, from, to)
|
||||
if (from != 0 || to != nil) && collection.respond_to?(:load_slice)
|
||||
collection.load_slice(from, to)
|
||||
else
|
||||
slice_collection_using_each(collection, from, to)
|
||||
end
|
||||
end
|
||||
|
||||
def self.non_blank_string?(collection)
|
||||
collection.is_a?(String) && collection != ''
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.slice_collection_using_each(collection, from, to)
|
||||
segments = []
|
||||
index = 0
|
||||
@@ -22,9 +37,5 @@ module Liquid
|
||||
|
||||
segments
|
||||
end
|
||||
|
||||
def self.non_blank_string?(collection)
|
||||
collection.is_a?(String) && collection != ''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user