From 3c13113daae2f60d37fa4d1a8902efe21dfa5269 Mon Sep 17 00:00:00 2001 From: Ghommie <42542238+Ghommie@users.noreply.github.com> Date: Mon, 6 Jan 2020 13:11:47 +0100 Subject: [PATCH] Fixes a long lasting runtime with filter data priority sorting. --- code/__HELPERS/cmp.dm | 5 ++++- code/game/atoms.dm | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/cmp.dm b/code/__HELPERS/cmp.dm index b0d606ea951..03ba8790530 100644 --- a/code/__HELPERS/cmp.dm +++ b/code/__HELPERS/cmp.dm @@ -35,7 +35,7 @@ GLOBAL_VAR_INIT(cmp_field, "name") /proc/cmp_datum_text_dsc(datum/a, datum/b, variable) return sorttext(a.vars[variable], b.vars[variable]) - + /proc/cmp_ckey_asc(client/a, client/b) return sorttext(b.ckey, a.ckey) @@ -51,6 +51,9 @@ GLOBAL_VAR_INIT(cmp_field, "name") /proc/cmp_subsystem_priority(datum/controller/subsystem/a, datum/controller/subsystem/b) return a.priority - b.priority +/proc/cmp_filter_data_priority(list/A, list/B) + return A["priority"] - B["priority"] + /proc/cmp_timer(datum/timedevent/a, datum/timedevent/b) return a.timeToRun - b.timeToRun diff --git a/code/game/atoms.dm b/code/game/atoms.dm index c355e700326..0da25b09c2e 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -1158,8 +1158,7 @@ target.log_message(reverse_message, LOG_ATTACK, color="orange", log_globally=FALSE) /atom/movable/proc/add_filter(name,priority,list/params) - if(!filter_data) - filter_data = list() + LAZYINITLIST(filter_data) var/list/p = params.Copy() p["priority"] = priority filter_data[name] = p @@ -1167,7 +1166,7 @@ /atom/movable/proc/update_filters() filters = null - sortTim(filter_data,associative = TRUE) + filter_data = sortTim(filter_data, /proc/cmp_filter_data_priority, TRUE) for(var/f in filter_data) var/list/data = filter_data[f] var/list/arguments = data.Copy()