tiny optimisation

This commit is contained in:
BlackMajor
2021-01-17 17:59:03 +13:00
parent b95c39e483
commit 96d2868d2d
3 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
GLOBAL_LIST_EMPTY(typelists)
#ifndef TESTING
/datum/proc/typelist(key, list/values = list())
var/list/mytypelist = GLOB.typelists[type] || (GLOB.typelists[type] = list())
return mytypelist[key] || (mytypelist[key] = values.Copy())
#else
// mostly the same code as above, just more verbose, slower and has tallying for saved lists
/datum/proc/typelist(key, list/values)
if (!values)
values = list()
GLOB.typelistkeys |= key
if (GLOB.typelists[type])
if (GLOB.typelists[type][key])
GLOB.typelists[type]["[key]-saved"]++
return GLOB.typelists[type][key]
else
GLOB.typelists[type][key] = values.Copy()
else
GLOB.typelists[type] = list()
GLOB.typelists[type][key] = values.Copy()
return GLOB.typelists[type][key]
GLOBAL_LIST_EMPTY(typelistkeys)
/proc/tallytypelistsavings()
var/savings = list()
var/saveditems = list()
for (var/key in GLOB.typelistkeys)
savings[key] = 0
saveditems[key] = 0
for (var/type in GLOB.typelists)
for (var/saving in savings)
if (GLOB.typelists[type]["[saving]-saved"])
savings[saving] += GLOB.typelists[type]["[saving]-saved"]
saveditems[saving] += (GLOB.typelists[type]["[saving]-saved"] * length(GLOB.typelists[type][saving]))
for (var/saving in savings)
to_chat(world, "Savings for [saving]: [savings[saving]] lists, [saveditems[saving]] items")
#endif

View File

@@ -104,8 +104,11 @@
var/tip_timer // reference to timer id for a tooltip we might open soon
/obj/item/New()
..()
/obj/item/Initialize(mapload)
. = ..()
/*
if(islist(origin_tech))
origin_tech = typelist(NAMEOF(src, origin_tech), origin_tech)*/
if(embed_chance < 0)
if(sharp)
embed_chance = max(5, round(force/w_class))

View File

@@ -144,6 +144,7 @@
#include "code\_helpers\time.dm"
#include "code\_helpers\turfs.dm"
#include "code\_helpers\type2type.dm"
#include "code\_helpers\typelists.dm"
#include "code\_helpers\unsorted.dm"
#include "code\_helpers\unsorted_vr.dm"
#include "code\_helpers\view.dm"