Speeds up saycode by almost doubling get_hearers_in_view() performance (#32650)

* The sun is also a warrior

* Knowledge can also destroy

* nor can the kindest will preserve you from the kill
This commit is contained in:
vuonojenmustaturska
2017-11-16 13:08:53 +02:00
committed by CitadelStationBot
parent 286442cf4a
commit 23f2815bb7
+18 -7
View File
@@ -214,17 +214,28 @@
/proc/get_hearers_in_view(R, atom/source)
// Returns a list of hearers in view(R) from source (ignoring luminosity). Used in saycode.
var/turf/T = get_turf(source)
var/list/hear = list()
. = list()
if(!T)
return hear
return
var/list/range = get_hear(R, T)
for(var/atom/movable/A in range)
hear |= recursive_hear_check(A)
return hear
var/list/processing_list = list()
if (R == 0) // if the range is zero, we know exactly where to look for, we can skip view
processing_list += T.contents // We can shave off one iteration by assuming turfs cannot hear
else // A variation of get_hear inlined here to take advantage of the compiler's fastpath for obj/mob in view
var/lum = T.luminosity
T.luminosity = 6 // This is the maximum luminosity
processing_list = viewers(R, T)
for(var/obj/O in view(R, T))
processing_list += O
T.luminosity = lum
while(processing_list.len) // recursive_hear_check inlined here
var/atom/A = processing_list[1]
if(A.flags_1 & HEAR_1)
. += A
processing_list.Cut(1, 2)
processing_list += A.contents
/proc/get_mobs_in_radio_ranges(list/obj/item/device/radio/radios)