From 23f2815bb7309dcb837c3dc2e26009737cd7a48e Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Thu, 16 Nov 2017 13:08:53 +0200 Subject: [PATCH 1/2] 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 --- code/__HELPERS/game.dm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index caddfdf509..39960e46b8 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -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)