From 414844604466d64e5f73ffe2e2d9b1ce1cd5a5c9 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Mon, 16 Oct 2017 23:34:05 -0700 Subject: [PATCH 1/2] Removing 210mb of wasted memory usage --- code/__HELPERS/_lists.dm | 1 + code/_globalvars/lists/typecache.dm | 2 +- code/game/machinery/_machinery.dm | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/_lists.dm b/code/__HELPERS/_lists.dm index e5478adff47..11fcf5041c9 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 THISORTHAT(THIS, THAT) (THIS ? THIS : THAT) #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 d83c708131e..0a6cdeafea9 100644 --- a/code/_globalvars/lists/typecache.dm +++ b/code/_globalvars/lists/typecache.dm @@ -5,5 +5,5 @@ GLOBAL_LIST_INIT(typecache_mob, typecacheof(list(/mob))) - +GLOBAL_LIST_INIT(typecache_living, typecacheof(list(/mob/living))) diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index fe70f43d7a0..bd72c58a6da 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, THISORTHAT(occupant_typecache, typecache_living))) continue var/atom/movable/AM = am if(AM.has_buckled_mobs()) From 7060428b6680498d5dc3400ba864ef48b181c213 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Mon, 16 Oct 2017 23:54:54 -0700 Subject: [PATCH 2/2] The choice is not mine --- code/__HELPERS/_lists.dm | 2 +- code/game/machinery/_machinery.dm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/__HELPERS/_lists.dm b/code/__HELPERS/_lists.dm index 11fcf5041c9..c8163f980af 100644 --- a/code/__HELPERS/_lists.dm +++ b/code/__HELPERS/_lists.dm @@ -485,7 +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 THISORTHAT(THIS, THAT) (THIS ? THIS : THAT) + #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/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index bd72c58a6da..60260d2a4fa 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -190,7 +190,7 @@ Class Procs: density = TRUE if(!target) for(var/am in loc) - if(!is_type_in_typecache(am, THISORTHAT(occupant_typecache, typecache_living))) + if(!is_type_in_typecache(am, (occupant_typecache || GLOB.typecache_living))) continue var/atom/movable/AM = am if(AM.has_buckled_mobs())