Optimize perf. of crafting algo. (55% savings)

This commit is contained in:
Andrew Miner
2015-02-22 23:19:12 -08:00
parent 0ec909a11e
commit aa42053c6e
2 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ module.exports = class ModVersion extends BaseModel
findRecipes: (itemSlug, result=[], options={})-> findRecipes: (itemSlug, result=[], options={})->
options.onlyPrimary ?= false options.onlyPrimary ?= false
for k, recipe of @_recipes for recipe in _.values @_recipes
if options.onlyPrimary if options.onlyPrimary
if recipe.itemSlug.matches itemSlug if recipe.itemSlug.matches itemSlug
result.push recipe result.push recipe
+7 -4
View File
@@ -100,11 +100,14 @@ module.exports = class Recipe extends BaseModel
return 0 return 0
produces: (itemSlug)-> produces: (itemSlug)->
for stack in @output if not @_produces?
if stack.itemSlug.matches itemSlug @_produces = {}
return true
return false for stack in @output
@_produces[stack.itemSlug.qualified] = true
@_produces[stack.itemSlug.item] = true
return @_produces[itemSlug.qualified]
requires: (itemSlug)-> requires: (itemSlug)->
for stack in @input for stack in @input