Skip to content

Commit

Permalink
Use Enumerable#sum in ElectricityDemandCurve
Browse files Browse the repository at this point in the history
* sum is slightly faster.

* Moved the implementation to `ElectricityDemandCurve#[]`, since this
  if more commonly called than `get`.
  • Loading branch information
antw committed Oct 29, 2018
1 parent 9685705 commit 729e77a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/qernel/plugins/fever/electricity_demand_curve.rb
Expand Up @@ -19,15 +19,15 @@ def length
end

def get(frame)
@producers.sum { |prod| prod.source_at(frame) }
self[frame]
end

def first
get(0)
end

def [](frame)
get(frame)
@producers.sum(0.0) { |prod| prod.source_at(frame) }
end

# For some reason, Merit calls curve#values#[]
Expand Down

0 comments on commit 729e77a

Please sign in to comment.