From e407a0af97107d95eefc1c319f3ec224b5767680 Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 2 Jun 2023 19:05:50 +0200 Subject: [PATCH] Optimize MaplistMethod_Shuffle by reducing the number of strcats --- qcsrc/server/intermission.qc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qcsrc/server/intermission.qc b/qcsrc/server/intermission.qc index b2652f7d8..360c15c94 100644 --- a/qcsrc/server/intermission.qc +++ b/qcsrc/server/intermission.qc @@ -232,11 +232,21 @@ float MaplistMethod_Shuffle(float exponent) // more clever shuffling // insert the current map there newlist = ""; - for(j = 1; j < insertpos; ++j) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above - newlist = strcat(newlist, " ", argv(j)); + for(j = 1; j < insertpos; ) // i == 1: no loop, will be inserted as first; however, i == 1 has been excluded above + { + if (j + 2 < insertpos) + newlist = strcat(newlist, " ", argv(j++), " ", argv(j++), " ", argv(j++)); + else + newlist = strcat(newlist, " ", argv(j++)); + } newlist = strcat(newlist, " ", argv(0)); // now insert the just selected map - for(j = insertpos; j < Map_Count; ++j) // i == Map_Count: no loop, has just been inserted as last - newlist = strcat(newlist, " ", argv(j)); + for(j = insertpos; j < Map_Count; ) // i == Map_Count: no loop, has just been inserted as last + { + if (j + 2 < Map_Count) + newlist = strcat(newlist, " ", argv(j++), " ", argv(j++), " ", argv(j++)); + else + newlist = strcat(newlist, " ", argv(j++)); + } newlist = substring(newlist, 1, strlen(newlist) - 1); cvar_set("g_maplist", newlist); Map_Count = tokenizebyseparator(autocvar_g_maplist, " "); -- 2.39.2