Files
Bubberstation/code/__HELPERS/string_numbers_lists.dm
SkyratBot 888801fd05 [MIRROR] Adds a unit test to stop elements from using identical lists for their arguments. [MDB IGNORE] (#22732)
* Adds a unit test to stop elements from using identical lists for their arguments. (#76322)

## About The Pull Request
Ok, so a few days ago I made an issue report about multiple instances of
identical elements being generated because of uncached lists.
ninjanomnom (the mind being the element datums) cleared it up and said
an implementation of GetIdFromArguments() that also checks the list
contents wouldn't be worth the performance cost, while adding that a
unit test should be written to check that it doesn't happen at least
during init, which should catch a good chunk of cases.

Also, i'm stopping RemoveElement() from initializing new elements
whenever a cached element is not found. Ideally, there should be a focus
only unit test for that too, but that's something we should tackle on a
different PR.

Some of the code comments may be a tad inaccurate, as much as I'd like
to blame drowsiness for it. Regardless, the unit test takes less than
0.2 seconds to complete on my potato so it's fairly lite.

## Why It's Good For The Game
This will close #76279.

## Changelog
No player-facing change to be logged.

* Adds a unit test to stop elements from using identical lists for their arguments.

* Fixes unit test

* seeing double

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
Co-authored-by: Giz <13398309+vinylspiders@users.noreply.github.com>
2023-07-27 20:08:55 -04:00

20 lines
441 B
Plaintext

GLOBAL_LIST_EMPTY(string_numbers_lists)
/**
* Caches lists of numeric values.
*/
/datum/proc/string_numbers_list(list/values)
//Just to to be extra-safe. If you try to shove in text or paths, you deserve the runtime errors.
var/list/sum = 0
for(var/number in values)
sum += number
var/string_id = values.Join("-")
. = GLOB.string_numbers_lists[string_id]
if(.)
return .
return GLOB.string_numbers_lists[string_id] = values