Repair is type in list (#10229)

Using isnum is unreliable for detecting nonstandard formats of already associative lists. Causing them to be overriden with the type cache.

Checking isnull instead will allow us to detect strings, numbers, lists, typepaths, basically everything that we want to check to make sure this isn't already an associative list.

Fixes #10225
Fixes #10224
This commit is contained in:
clusterfack
2016-05-27 14:53:47 -05:00
parent 0893e93e4d
commit a13c6c9fcb
2 changed files with 13 additions and 4 deletions

View File

@@ -58,16 +58,24 @@
//Checks for specific types in a list //Checks for specific types in a list
/proc/is_type_in_list(datum/A, list/L) /proc/is_type_in_list(datum/A, list/L)
if (!L.len || !A) if(!L.len || !A)
return 0 return 0
if (!isnum(L[L[1]])) //Has this not been converted to an associative list?
generate_type_list_cache(L) //Convert it to an associative list if(L[L[1]] != MAX_VALUE) //Is this already a generated typecache
if(isnull(L[L[1]])) //It's not a typecache, so now we'll check if its an associative list or not
generate_type_list_cache(L) //Convert it to an associative list format for speed in access
else //Else this is meant to be an associative list, we can't reformat it
for(var/type in L)
if(istype(A, type))
return 1
return 0
return L[A.type] return L[A.type]
/proc/generate_type_list_cache(L) /proc/generate_type_list_cache(L)
for(var/type in L) for(var/type in L)
for(var/T in typesof(type)) //Gather all possible typepaths into an associative list for(var/T in typesof(type)) //Gather all possible typepaths into an associative list
L[T] = 1 //Set them equal to one L[T] = MAX_VALUE //Set them equal to the max value which is unlikely to collide with any other pregenerated value
//Empties the list by setting the length to 0. Hopefully the elements get garbage collected //Empties the list by setting the length to 0. Hopefully the elements get garbage collected
/proc/clearlist(list/list) /proc/clearlist(list/list)

View File

@@ -13,6 +13,7 @@
#define PROFILE_MACHINES // Disable when not debugging. #define PROFILE_MACHINES // Disable when not debugging.
#define ARBITRARILY_LARGE_NUMBER 10000 //Used in delays.dm and vehicle.dm. Upper limit on delays #define ARBITRARILY_LARGE_NUMBER 10000 //Used in delays.dm and vehicle.dm. Upper limit on delays
#define MAX_VALUE 65535
#ifdef PROFILE_MACHINES #ifdef PROFILE_MACHINES
#define CHECK_DISABLED(TYPE) if(disable_##TYPE) return #define CHECK_DISABLED(TYPE) if(disable_##TYPE) return