Files
Bubberstation/code/__HELPERS/string_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

32 lines
1.3 KiB
Plaintext

GLOBAL_LIST_EMPTY(string_lists)
/**
* Caches lists with non-numeric stringify-able values (text or typepath).
*/
/proc/string_list(list/values)
var/string_id = values.Join("-")
. = GLOB.string_lists[string_id]
if(.)
return .
return GLOB.string_lists[string_id] = values
///A wrapper for baseturf string lists, to offer support of non list values, and a stack_trace if we have major issues
/proc/baseturfs_string_list(list/values, turf/baseturf_holder)
if(!islist(values))
return values //baseturf things
// return values
if(length(values) > 10)
stack_trace("The baseturfs list of [baseturf_holder] at [baseturf_holder.x], [baseturf_holder.y], [baseturf_holder.x] is [length(values)], it should never be this long, investigate. I've set baseturfs to a flashing wall as a visual queue")
baseturf_holder.ChangeTurf(/turf/closed/indestructible/baseturfs_ded, list(/turf/closed/indestructible/baseturfs_ded), flags = CHANGETURF_FORCEOP)
return string_list(list(/turf/closed/indestructible/baseturfs_ded)) //I want this reported god damn it
return string_list(values)
/turf/closed/indestructible/baseturfs_ded
name = "Report this"
desc = "It looks like base turfs went to the fucking moon, TELL YOUR LOCAL CODER TODAY"
icon = 'icons/turf/debug.dmi'
icon_state = "fucked_baseturfs"