mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -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
|
from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
|
||||||
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
|
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
|
length = collection.length
|
||||||
|
|
||||||
|
|||||||
@@ -75,11 +75,7 @@ module Liquid
|
|||||||
limit = context[@attributes['limit']]
|
limit = context[@attributes['limit']]
|
||||||
to = limit ? limit.to_i + from : nil
|
to = limit ? limit.to_i + from : nil
|
||||||
|
|
||||||
segment = if (from != 0 || to != nil) && collection.respond_to?(:load_slice)
|
segment = Utils.slice_collection(collection, from, to)
|
||||||
collection.load_slice(from, to)
|
|
||||||
else
|
|
||||||
Utils.slice_collection_using_each(collection, from, to)
|
|
||||||
end
|
|
||||||
|
|
||||||
return render_else(context) if segment.empty?
|
return render_else(context) if segment.empty?
|
||||||
|
|
||||||
|
|||||||
+15
-4
@@ -1,5 +1,20 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
module Utils
|
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)
|
def self.slice_collection_using_each(collection, from, to)
|
||||||
segments = []
|
segments = []
|
||||||
index = 0
|
index = 0
|
||||||
@@ -22,9 +37,5 @@ module Liquid
|
|||||||
|
|
||||||
segments
|
segments
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.non_blank_string?(collection)
|
|
||||||
collection.is_a?(String) && collection != ''
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user