Skip to content

Commit a965e5a

Browse files
committed
Optimize tight loop
It seems true is no longer returned by any rule validation
1 parent 401ded3 commit a965e5a

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/ice_cube/validated_rule.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,19 @@ def find_acceptable_time_before(boundary)
140140
true
141141
end
142142

143+
# Returns true if all validations for the current rule match
144+
# otherwise false and shifts to the first (largest) unmatched offset
145+
#
143146
def validation_accepts_or_updates_time?(validations_for_type)
144-
res = validated_results(validations_for_type)
145-
return true if res.any? { |r| r.nil? || r == 0 }
146-
return nil if res.all? { |r| r == true }
147-
res.reject! { |r| r == true }
147+
res = validations_for_type.each_with_object([]) do |validation, offsets|
148+
r = validation.validate(@time, @schedule)
149+
return true if r.nil? || r == 0
150+
offsets << r
151+
end
148152
shift_time_by_validation(res, validations_for_type.first)
149153
false
150154
end
151155

152-
def validated_results(validations_for_type)
153-
validations_for_type.map do |validation|
154-
validation.validate(@time, @schedule)
155-
end
156-
end
157-
158156
def shift_time_by_validation(res, validation)
159157
return unless (interval = res.min)
160158
wrapper = TimeUtil::TimeWrapper.new(@time, validation.dst_adjust?)

0 commit comments

Comments
 (0)