Improves select_recipe. (#8141)

* select_recipe improvement

Removes the call to Timsort and the recipe comparator proc;
uses a handrolled implementation of
`argmax(items + reagents + fruit)` instead.
This reduces the memory footprint of `select_recipe`
as well as the amount of processing needed to select the optimal recipe.

* angelogchay
This commit is contained in:
MarinaGryphon
2021-06-18 18:06:27 -05:00
committed by GitHub
parent 1672a51eff
commit c224b192a9
3 changed files with 44 additions and 15 deletions

View File

@@ -57,12 +57,6 @@
if (!.)
. = B[STAT_ENTRY_COUNT] - A[STAT_ENTRY_COUNT]
// Compares complexity of recipes for use in cooking, etc. This is for telling which recipe to make, not for showing things to the player.
/proc/cmp_recipe_complexity_dsc(datum/recipe/A, datum/recipe/B)
var/a_score = LAZYLEN(A.items) + LAZYLEN(A.reagents) + LAZYLEN(A.fruit)
var/b_score = LAZYLEN(B.items) + LAZYLEN(B.reagents) + LAZYLEN(B.fruit)
return b_score - a_score
/proc/cmp_typepaths_asc(A, B)
return sorttext("[B]","[A]")