Merge pull request #10640 from VOREStation/upstream-merge-8122

[MIRROR] Make req_[one_]access lazy
This commit is contained in:
Novacat
2021-06-14 13:34:47 -04:00
committed by GitHub
3 changed files with 12 additions and 23 deletions
+1 -1
View File
@@ -39,7 +39,7 @@
#define LAZYACCESSASSOC(L, I, K) L ? L[I] ? L[I][K] ? L[I][K] : null : null : null
// Null-safe L.Cut()
#define LAZYCLEARLIST(L) if(L) L.Cut()
#define LAZYCLEARLIST(L) if(L) { L.Cut(); L = null; }
// Reads L or an empty list if L is not a list. Note: Does NOT assign, L may be an expression.
#define SANITIZE_LIST(L) ( islist(L) ? L : list() )
+2 -2
View File
@@ -205,11 +205,11 @@ SUBSYSTEM_DEF(supply)
else if(islist(SP.access) && SP.one_access)
var/list/L = SP.access // access var is a plain var, we need a list
A.req_one_access = L.Copy()
A.req_access = null
LAZYCLEARLIST(A.req_access)
else if(islist(SP.access) && !SP.one_access)
var/list/L = SP.access
A.req_access = L.Copy()
A.req_one_access = null
LAZYCLEARLIST(A.req_one_access)
else
log_debug("<span class='danger'>Supply pack with invalid access restriction [SP.access] encountered!</span>")
+9 -20
View File
@@ -28,32 +28,21 @@
return has_access(req_access, req_one_access, L)
/proc/has_access(var/list/req_access, var/list/req_one_access, var/list/accesses)
// Doesn't have access lists, always works
if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access))
return TRUE
// Didn't pass anything to compare
if(!LAZYLEN(accesses))
return FALSE
// req_access list has priority if set
// Requires at least every access in list
if(LAZYLEN(req_access))
for(var/req in req_access)
if(!(req in accesses))
return FALSE
// Wasn't missing any accesses
return TRUE
for(var/req in req_access)
if(!(req in accesses))
return FALSE
// req_one_access is secondary if set
// Requires at least one access in list
for(var/req in req_one_access)
if(req in accesses)
// Found at least one
return TRUE
if(LAZYLEN(req_one_access))
for(var/req in req_one_access)
if(req in accesses)
return TRUE
return FALSE
// Didn't find anything that matched
return FALSE
return TRUE
/proc/get_centcom_access(job)
switch(job)