From e3729033d2bd310dffcf29c75ab62401a16a3201 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Mon, 16 May 2016 10:23:19 -0700 Subject: [PATCH] Makes is_type_in_list() much faster (thanks remie) --- code/__HELPERS/lists.dm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 172418498c3..58a87f374a7 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -53,10 +53,16 @@ //Checks for specific types in a list /proc/is_type_in_list(atom/A, list/L) + if (!L.len) + return 0 + if (!isnum(L[L[1]])) + generate_type_list_cache(L) + return L[A.type] + +/proc/generate_type_list_cache(L) for(var/type in L) - if(istype(A, type)) - return 1 - return 0 + for(var/T in typesof(type)) + L[T] = 1 //Empties the list by setting the length to 0. Hopefully the elements get garbage collected /proc/clearlist(list/list)