From 7f9d13ab42cfb1f5a6a1a59cc2b0cf06fbbc558b Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Tue, 17 Oct 2017 22:18:19 -0500 Subject: [PATCH] [MIRROR] Removes 200mb of wasted memory usage (#3472) * Merge pull request #31835 from MrStonedOne/coiax-is-fired---again Removes 200mb of wasted memory usage * Removes 200mb of wasted memory usage --- code/__HELPERS/_lists.dm | 1 + code/_globalvars/lists/typecache.dm | 4 +++- code/game/machinery/_machinery.dm | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/_lists.dm b/code/__HELPERS/_lists.dm index e5478adff4..c8163f980a 100644 --- a/code/__HELPERS/_lists.dm +++ b/code/__HELPERS/_lists.dm @@ -485,6 +485,7 @@ //Picks from the list, with some safeties, and returns the "default" arg if it fails #define DEFAULTPICK(L, default) ((islist(L) && length(L)) ? pick(L) : default) + #define LAZYINITLIST(L) if (!L) L = list() #define UNSETEMPTY(L) if (L && !L.len) L = null #define LAZYREMOVE(L, I) if(L) { L -= I; if(!L.len) { L = null; } } diff --git a/code/_globalvars/lists/typecache.dm b/code/_globalvars/lists/typecache.dm index c6893542a3..dfa99b6706 100644 --- a/code/_globalvars/lists/typecache.dm +++ b/code/_globalvars/lists/typecache.dm @@ -4,6 +4,8 @@ //Note: typecache can only replace istype if you know for sure the thing is at least a datum. GLOBAL_LIST_INIT(typecache_mob, typecacheof(list(/mob))) + +GLOBAL_LIST_INIT(typecache_living, typecacheof(list(/mob/living))) + GLOBAL_LIST_INIT(typecache_machine_or_structure, typecacheof(list(/obj/machinery))|typecacheof(list(/obj/structure))) - diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 7858480f5c..24c0e0b388 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -117,7 +117,7 @@ Class Procs: var/panel_open = FALSE var/state_open = FALSE var/critical_machine = FALSE //If this machine is critical to station operation and should have the area be excempted from power failures. - var/list/occupant_typecache = list(/mob/living) // turned into typecache in Initialize + var/list/occupant_typecache //if set, turned into typecache in Initialize, other wise, defaults to mob/living typecache var/atom/movable/occupant = null var/unsecuring_tool = /obj/item/wrench var/interact_open = FALSE // Can the machine be interacted with when in maint/when the panel is open. @@ -141,7 +141,8 @@ Class Procs: START_PROCESSING(SSfastprocess, src) power_change() - occupant_typecache = typecacheof(occupant_typecache) + if (occupant_typecache) + occupant_typecache = typecacheof(occupant_typecache) /obj/machinery/Destroy() GLOB.machines.Remove(src) @@ -189,7 +190,7 @@ Class Procs: density = TRUE if(!target) for(var/am in loc) - if(!is_type_in_typecache(am, occupant_typecache)) + if(!is_type_in_typecache(am, (occupant_typecache || GLOB.typecache_living))) continue var/atom/movable/AM = am if(AM.has_buckled_mobs())