From 63715c56b176d0183a7a11132f793bb1763f2ede Mon Sep 17 00:00:00 2001 From: vuonojenmustaturska Date: Sun, 26 Aug 2018 03:49:26 +0300 Subject: [PATCH 1/4] Small refactor to to_chat to get rid of needless list-wrapping (#39899) This is frequently called from inside a loop. Probably no measurable performance impact but I sleep easier knowing we don't do this. Also includes a helper define for getting a client from a clientful thing. I also shuffled some things around for more nano-optimizations. --- code/__DEFINES/misc.dm | 2 ++ code/modules/admin/verbs/borgpanel.dm | 19 ++++++----- code/modules/goonchat/browserOutput.dm | 45 +++++++++++++++++++------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 8f274fcde460..4e306d224d57 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -457,3 +457,5 @@ GLOBAL_LIST_INIT(pda_styles, list(MONO, VT, ORBITRON, SHARE)) #define CAMERA_NO_GHOSTS 0 #define CAMERA_SEE_GHOSTS_BASIC 1 #define CAMERA_SEE_GHOSTS_ORBIT 2 + +#define CLIENT_FROM_VAR(I) (ismob(I) ? I:client : (istype(I, /client) ? I : (istype(I, /datum/mind) ? I:current?:client : null))) diff --git a/code/modules/admin/verbs/borgpanel.dm b/code/modules/admin/verbs/borgpanel.dm index ec921e78bc6f..6295d4be43e9 100644 --- a/code/modules/admin/verbs/borgpanel.dm +++ b/code/modules/admin/verbs/borgpanel.dm @@ -21,18 +21,17 @@ var/mob/living/silicon/robot/borg var/user -/datum/borgpanel/New(user, mob/living/silicon/robot/borg) - if(!istype(borg)) +/datum/borgpanel/New(to_user, mob/living/silicon/robot/to_borg) + if(!istype(to_borg)) CRASH("Borg panel is only available for borgs") qdel(src) - if (istype(user, /mob)) - var/mob/M = user - if (!M.client) - CRASH("Borg panel attempted to open to a mob without a client") - src.user = M.client - else - src.user = user - src.borg = borg + + user = CLIENT_FROM_VAR(to_user) + + if (!user) + CRASH("Borg panel attempted to open to a mob without a client") + + borg = to_borg /datum/borgpanel/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.admin_state) ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open) diff --git a/code/modules/goonchat/browserOutput.dm b/code/modules/goonchat/browserOutput.dm index 847b6b55e992..98bd513fc9f1 100644 --- a/code/modules/goonchat/browserOutput.dm +++ b/code/modules/goonchat/browserOutput.dm @@ -191,29 +191,23 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic log_world("\[[time2text(world.realtime, "YYYY-MM-DD hh:mm:ss")]\] Client: [(src.owner.key ? src.owner.key : src.owner)] triggered JS error: [error]") //Global chat procs - /proc/to_chat(target, message, handle_whitespace=TRUE) if(!target) return //Ok so I did my best but I accept that some calls to this will be for shit like sound and images //It stands that we PROBABLY don't want to output those to the browser output so just handle them here - if (istype(message, /image) || istype(message, /sound) || istype(target, /savefile)) + if (istype(target, /savefile)) CRASH("Invalid message! [message]") if(!istext(message)) + if (istype(message, /image) || istype(message, /sound)) + CRASH("Invalid message! [message]") return if(target == world) target = GLOB.clients - var/list/targets - if(!islist(target)) - targets = list(target) - else - targets = target - if(!targets.len) - return var/original_message = message //Some macros remain in the string even after parsing and fuck up the eventual output message = replacetext(message, "\improper", "") @@ -221,6 +215,7 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if(handle_whitespace) message = replacetext(message, "\n", "
") message = replacetext(message, "\t", "[GLOB.TAB][GLOB.TAB]") +<<<<<<< HEAD message = to_utf8(message, target) // yogs - LibVG for(var/I in targets) @@ -237,20 +232,46 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if(M.current && M.current.client) C = M.current.client +======= + + if(islist(target)) + // Do the double-encoding outside the loop to save nanoseconds + var/twiceEncoded = url_encode(url_encode(message)) + for(var/I in target) + var/client/C = CLIENT_FROM_VAR(I) //Grab us a client if possible + + if (!C) + continue + + //Send it to the old style output window. + SEND_TEXT(C, original_message) + + if(!C.chatOutput || C.chatOutput.broken) // A player who hasn't updated his skin file. + continue + + if(!C.chatOutput.loaded) + //Client still loading, put their messages in a queue + C.chatOutput.messageQueue += message + continue + + C << output(twiceEncoded, "browseroutput:output") + else + var/client/C = CLIENT_FROM_VAR(target) //Grab us a client if possible +>>>>>>> bc7006f266... Small refactor to to_chat to get rid of needless list-wrapping (#39899) if (!C) - continue + return //Send it to the old style output window. SEND_TEXT(C, original_message) if(!C.chatOutput || C.chatOutput.broken) // A player who hasn't updated his skin file. - continue + return if(!C.chatOutput.loaded) //Client still loading, put their messages in a queue C.chatOutput.messageQueue += message - continue + return // url_encode it TWICE, this way any UTF-8 characters are able to be decoded by the Javascript. C << output(url_encode(url_encode(message)), "browseroutput:output") From 458858ee762d5b7de1d73421e1b218afb69f1248 Mon Sep 17 00:00:00 2001 From: Joe Schmoe Date: Sun, 26 Aug 2018 14:27:59 +0200 Subject: [PATCH 3/4] resolve merge conflict --- code/modules/goonchat/browserOutput.dm | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/code/modules/goonchat/browserOutput.dm b/code/modules/goonchat/browserOutput.dm index 98bd513fc9f1..b533cd55e8bd 100644 --- a/code/modules/goonchat/browserOutput.dm +++ b/code/modules/goonchat/browserOutput.dm @@ -215,31 +215,13 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if(handle_whitespace) message = replacetext(message, "\n", "
") message = replacetext(message, "\t", "[GLOB.TAB][GLOB.TAB]") -<<<<<<< HEAD message = to_utf8(message, target) // yogs - LibVG - - for(var/I in targets) - //Grab us a client if possible - var/client/C - if (ismob(I)) - var/mob/M = I - if(M.client) - C = M.client - else if(istype(I, /client)) - C = I - else if(istype(I, /datum/mind)) - var/datum/mind/M = I - if(M.current && M.current.client) - C = M.current.client - -======= if(islist(target)) // Do the double-encoding outside the loop to save nanoseconds var/twiceEncoded = url_encode(url_encode(message)) for(var/I in target) var/client/C = CLIENT_FROM_VAR(I) //Grab us a client if possible - if (!C) continue @@ -257,8 +239,6 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic C << output(twiceEncoded, "browseroutput:output") else var/client/C = CLIENT_FROM_VAR(target) //Grab us a client if possible ->>>>>>> bc7006f266... Small refactor to to_chat to get rid of needless list-wrapping (#39899) - if (!C) return From e7da06cfc7fead7fbe8d6a1a4714f104f05369ef Mon Sep 17 00:00:00 2001 From: Nich Date: Wed, 29 Aug 2018 15:38:46 +0200 Subject: [PATCH 4/4] lol --- code/modules/goonchat/browserOutput.dm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/modules/goonchat/browserOutput.dm b/code/modules/goonchat/browserOutput.dm index b533cd55e8bd..adce78f24d9f 100644 --- a/code/modules/goonchat/browserOutput.dm +++ b/code/modules/goonchat/browserOutput.dm @@ -215,12 +215,12 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if(handle_whitespace) message = replacetext(message, "\n", "
") message = replacetext(message, "\t", "[GLOB.TAB][GLOB.TAB]") - message = to_utf8(message, target) // yogs - LibVG if(islist(target)) // Do the double-encoding outside the loop to save nanoseconds var/twiceEncoded = url_encode(url_encode(message)) for(var/I in target) + message = to_utf8(message, I) // yogs - LibVG var/client/C = CLIENT_FROM_VAR(I) //Grab us a client if possible if (!C) continue @@ -242,6 +242,8 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if (!C) return + message = to_utf8(message, target) // yogs - LibVG + //Send it to the old style output window. SEND_TEXT(C, original_message)