Improves performance of 2 reagent operations (#84411)

## About The Pull Request
1. Removes **2 WHOLE** `update_total()` calls from `trans_to()`. This is
the hottest proc in plumbing & in a large majority of other reagent
operations so it's a big win. `add_reagent()` & `remove_reagent()`
already calls `update_total()` for us so we don't need them. Its free
performance!!
2. `remove_reagent()` only calls `update_total()` & `handle_reactions()`
once when removing subtypes of a reagent compared to repeatedly calling
these hot procs every iteration

## Changelog
🆑
code: Improves cpu performance of transferring & removing reagents
/🆑
This commit is contained in:
SyncIt21
2024-07-03 22:50:34 +02:00
committed by GitHub
parent 7d6a6fec3b
commit 1be33aaaad
@@ -235,6 +235,7 @@
var/total_removed_amount = 0
var/remove_amount = 0
var/list/cached_reagents = reagent_list
var/list/removed_reagents = list()
for(var/datum/reagent/cached_reagent as anything in cached_reagents)
//check for specific type or subtypes
if(!include_subtypes)
@@ -243,19 +244,26 @@
else if(!istype(cached_reagent, reagent_type))
continue
//reduce the volume
remove_amount = min(cached_reagent.volume, amount)
cached_reagent.volume -= remove_amount
update_total()
if(!safety)//So it does not handle reactions when it need not to
handle_reactions()
SEND_SIGNAL(src, COMSIG_REAGENTS_REM_REAGENT, QDELING(cached_reagent) ? reagent_type : cached_reagent, amount)
//record the changes
removed_reagents += cached_reagent
total_removed_amount += remove_amount
//if we reached here means we have found our specific reagent type so break
if(!include_subtypes)
return total_removed_amount
break
//inform others about our reagents being removed
for(var/datum/reagent/removed_reagent as anything in cached_reagents)
SEND_SIGNAL(src, COMSIG_REAGENTS_REM_REAGENT, removed_reagent, amount)
//update the holder & handle reactions
update_total()
if(!safety)
handle_reactions()
return round(total_removed_amount, CHEMICAL_VOLUME_ROUNDING)
@@ -504,8 +512,6 @@
log_target.add_hiddenprint(transferred_by) //log prints so admins can figure out who touched it last.
log_combat(transferred_by, log_target, "transferred reagents to", my_atom, "which had [get_external_reagent_log_string(transfer_log)]")
update_total()
target_holder.update_total()
if(!no_react)
target_holder.handle_reactions()
src.handle_reactions()