From: Dr. Jaska Date: Fri, 15 Mar 2024 22:39:19 +0000 (+0000) Subject: micro-optimization chore: in for-loops change all post-{in,de}crements to pre-{in... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f963d587753ce1f8e48c8bf87b0bf860732986be;p=xonotic%2Fxonotic-data.pk3dir.git micro-optimization chore: in for-loops change all post-{in,de}crements to pre-{in,de}crements --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index e30f9bbcb..90917341a 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1381,7 +1381,7 @@ string translate_weaponarena(string s) int n = tokenizebyseparator(s, " & "); string wpn_list = ""; - for (int i = 0; i < n; i++) + for (int i = 0; i < n; ++i) { Weapon wep = Weapon_from_name(argv(i)); if (wep == WEP_Null) diff --git a/qcsrc/common/minigames/cl_minigames.qc b/qcsrc/common/minigames/cl_minigames.qc index eaf8e0d65..df6f77a4f 100644 --- a/qcsrc/common/minigames/cl_minigames.qc +++ b/qcsrc/common/minigames/cl_minigames.qc @@ -262,7 +262,7 @@ string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_ take_until = strlen(s); int skip = 0; - for ( int i = 0; i < take_until; i++ ) + for ( int i = 0; i < take_until; ++i ) if ( substring(s,i,1) == "\n" ) { take_until = i; @@ -364,7 +364,7 @@ void minigame_cmd_workaround(float dummy, string...cmdargc) string cmd; cmd = "cmd minigame "; float i; - for ( i = 0; i < cmdargc; i++ ) + for ( i = 0; i < cmdargc; ++i ) cmd = strcat(cmd,...(i,string)); localcmd(strcat(cmd,"\n")); } diff --git a/qcsrc/common/minigames/minigame/nmm.qc b/qcsrc/common/minigames/minigame/nmm.qc index b550f79a3..a54df3b74 100644 --- a/qcsrc/common/minigames/minigame/nmm.qc +++ b/qcsrc/common/minigames/minigame/nmm.qc @@ -101,10 +101,10 @@ void nmm_spawn_tile_square( entity minig, int offset, int skip ) { int letter = offset; int number = offset; - for ( int i = 0; i < 3; i++ ) + for ( int i = 0; i < 3; ++i ) { number = offset; - for ( int j = 0; j < 3; j++ ) + for ( int j = 0; j < 3; ++j ) { if ( i != 1 || j != 1 ) nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1); @@ -175,7 +175,7 @@ bool nmm_tile_canmove(entity tile) bool nmm_in_mill_string(entity tile, string s) { int argc = tokenize(s); - for ( int i = 0; i < argc; i++ ) + for ( int i = 0; i < argc; ++i ) { entity e = nmm_find_tile(tile.owner,argv(i)); if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team ) @@ -223,7 +223,7 @@ int nmm_server_event(entity minigame, string event, ...) minigame.minigame_flags = NMM_TURN_PLACE|NMM_TURN_TEAM1; nmm_init_tiles(minigame); entity e; - for ( int i = 0; i < 7; i++ ) + for ( int i = 0; i < 7; ++i ) { e = msle_spawn(minigame,new(minigame_board_piece)); e.team = 1; diff --git a/qcsrc/common/minigames/minigame/pong.qc b/qcsrc/common/minigames/minigame/pong.qc index 4acad766c..17c92d8d6 100644 --- a/qcsrc/common/minigames/minigame/pong.qc +++ b/qcsrc/common/minigames/minigame/pong.qc @@ -162,7 +162,7 @@ void pong_ball_think(entity this) this.SendFlags |= MINIG_SF_UPDATE; int i; - for ( i = 1; i <= PONG_MAX_PLAYERS; i++ ) + for ( i = 1; i <= PONG_MAX_PLAYERS; ++i ) if ( pong_paddle_hit(this, i) ) { pong_paddle_bounce(this,i); @@ -357,7 +357,7 @@ int pong_server_event(entity minigame, string event, ...) entity player = ...(0,entity); int i; - for ( i = 0; i < PONG_MAX_PLAYERS; i++ ) + for ( i = 0; i < PONG_MAX_PLAYERS; ++i ) { if ( minigame.pong_paddles[i] == NULL ) { @@ -374,7 +374,7 @@ int pong_server_event(entity minigame, string event, ...) entity paddle; entity ai; int i; - for ( i = 0; i < PONG_MAX_PLAYERS; i++ ) + for ( i = 0; i < PONG_MAX_PLAYERS; ++i ) { paddle = minigame.pong_paddles[i]; if ( paddle != NULL && paddle.realowner == player ) @@ -403,7 +403,7 @@ int pong_server_event(entity minigame, string event, ...) minigame.SendFlags |= MINIG_SF_UPDATE; entity ball; - for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; j++ ) + for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; ++j ) { ball = msle_spawn(minigame,new(pong_ball)); ball.pong_length = autocvar_sv_minigames_pong_ball_radius; @@ -447,8 +447,8 @@ int pong_server_event(entity minigame, string event, ...) // potentially compiler bug int j; if ( minigame.minigame_flags & PONG_STATUS_WAIT ) - for ( j = 0; j < PONG_MAX_PLAYERS; j++ ) - //for ( int j = 0; j < PONG_MAX_PLAYERS; j++ ) + for ( j = 0; j < PONG_MAX_PLAYERS; ++j ) + //for ( int j = 0; j < PONG_MAX_PLAYERS; ++j ) { if ( minigame.pong_paddles[j] == NULL ) { @@ -466,7 +466,7 @@ int pong_server_event(entity minigame, string event, ...) if ( minigame.minigame_flags & PONG_STATUS_WAIT ) { entity paddle; - for ( int j = PONG_MAX_PLAYERS-1; j >= 0; j-- ) + for ( int j = PONG_MAX_PLAYERS-1; j >= 0; --j ) { paddle = minigame.pong_paddles[j]; if ( paddle != NULL && diff --git a/qcsrc/common/mutators/mutator/nades/nades.qc b/qcsrc/common/mutators/mutator/nades/nades.qc index 3f9e54cdb..e32cd20d8 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qc +++ b/qcsrc/common/mutators/mutator/nades/nades.qc @@ -24,7 +24,7 @@ entity Nade_TrailEffect(int proj, int nade_team) } FOREACH(Nades, true, { - for (int j = 0; j < 2; j++) + for (int j = 0; j < 2; ++j) { if (it.m_projectile[j] == proj) { @@ -390,7 +390,7 @@ void napalm_fountain_think(entity this) void nade_napalm_boom(entity this) { - for (int c = 0; c < autocvar_g_nades_napalm_ball_count; c++) + for (int c = 0; c < autocvar_g_nades_napalm_ball_count; ++c) nade_napalm_ball(this); entity fountain = new(nade_napalm_fountain); diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index 7888da7d1..9c8aeedec 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -136,7 +136,7 @@ REGISTRY_DEFINE_GET(Nades, NADE_TYPE_Null) Nade Nade_FromProjectile(int proj) { FOREACH(Nades, true, { - for (int j = 0; j < 2; j++) + for (int j = 0; j < 2; ++j) { if (it.m_projectile[j] == proj) return it; } diff --git a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc index a31eee2ba..a387af90f 100644 --- a/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc +++ b/qcsrc/common/mutators/mutator/sandbox/sv_sandbox.qc @@ -437,7 +437,7 @@ void sandbox_Database_Load() if(e.material) { // since objects are being loaded for the first time, precache material sounds for each - for (i = 1; i <= 5; i++) // 5 sounds in total + for (i = 1; i <= 5; ++i) // 5 sounds in total precache_sound(strcat("object/impact_", e.material, "_", ftos(i), ".wav")); } } @@ -714,7 +714,7 @@ MUTATOR_HOOKFUNCTION(sandbox, SV_ParseClientCommand) strfree(e.material); if(argv(3)) { - for (j = 1; j <= 5; j++) // precache material sounds, 5 in total + for (j = 1; j <= 5; ++j) // precache material sounds, 5 in total precache_sound(strcat("object/impact_", argv(3), "_", ftos(j), ".wav")); e.material = strzone(argv(3)); } diff --git a/qcsrc/common/notifications/all.qc b/qcsrc/common/notifications/all.qc index 58910887e..dd200973b 100644 --- a/qcsrc/common/notifications/all.qc +++ b/qcsrc/common/notifications/all.qc @@ -1181,7 +1181,7 @@ void Local_Notification_centerprint_Add( } void Local_Notification_Queue_Run(MSG net_type, entity notif) -{ +{ switch (net_type) { case MSG_ANNCE: @@ -1193,7 +1193,7 @@ void Local_Notification_Queue_Run(MSG net_type, entity notif) } void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time) -{ +{ // Guess length if required if(queue_time == 0) queue_time = soundlength(AnnouncerFilename(notif.nent_snd)); @@ -1205,11 +1205,11 @@ void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time) } else { // Put in queue if(notif_queue_length >= NOTIF_QUEUE_MAX) return; - + notif_queue_type[notif_queue_length] = net_type; notif_queue_entity[notif_queue_length] = notif; notif_queue_time[notif_queue_length] = notif_queue_next_time; - + notif_queue_next_time += queue_time; ++notif_queue_length; } @@ -1224,7 +1224,7 @@ void Local_Notification_Queue_Process() // Shift queue to the left --notif_queue_length; - for (int j = 0; j < notif_queue_length; j++) { + for (int j = 0; j < notif_queue_length; ++j) { notif_queue_type[j] = notif_queue_type[j+1]; notif_queue_entity[j] = notif_queue_entity[j+1]; notif_queue_time[j] = notif_queue_time[j+1]; diff --git a/qcsrc/common/physics/movetypes/movetypes.qc b/qcsrc/common/physics/movetypes/movetypes.qc index 73ceb57b0..2c54617ef 100644 --- a/qcsrc/common/physics/movetypes/movetypes.qc +++ b/qcsrc/common/physics/movetypes/movetypes.qc @@ -20,7 +20,7 @@ bool _Movetype_NudgeOutOfSolid_PivotIsKnownGood(entity this, vector pivot) // SV { vector stuckorigin = this.origin; vector goodmins = pivot, goodmaxs = pivot; - for(int bump = 0; bump < 6; bump++) + for(int bump = 0; bump < 6; ++bump) { int coord = 2 - (bump >> 1); int dir = (bump & 1); @@ -150,7 +150,7 @@ int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepno original_velocity = primal_velocity = this.velocity; - for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES;bumpcount++) + for(int bumpcount = 0;bumpcount < MAX_CLIP_PLANES; ++bumpcount) { if(this.velocity == '0 0 0') break; @@ -265,11 +265,11 @@ int _Movetype_FlyMove(entity this, float dt, bool applygravity, bool applystepno // modify original_velocity so it parallels all of the clip planes vector new_velocity = '0 0 0'; int plane; - for (plane = 0;plane < numplanes;plane++) + for (plane = 0;plane < numplanes; ++plane) { int newplane; new_velocity = _Movetype_ClipVelocity(original_velocity, planes[plane], 1); - for (newplane = 0;newplane < numplanes;newplane++) + for (newplane = 0;newplane < numplanes; ++newplane) { if(newplane != plane) { diff --git a/qcsrc/common/physics/movetypes/toss.qc b/qcsrc/common/physics/movetypes/toss.qc index 5c254811d..caf1fda47 100644 --- a/qcsrc/common/physics/movetypes/toss.qc +++ b/qcsrc/common/physics/movetypes/toss.qc @@ -48,7 +48,7 @@ void _Movetype_Physics_Toss(entity this, float dt) // SV_Physics_Toss this.angles = this.angles + this.avelocity * dt; float movetime = dt; - for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; bump++) + for (int bump = 0; bump < MAX_CLIP_PLANES && movetime > 0; ++bump) { if(this.velocity == '0 0 0') break; diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 9744eda19..c2adabb1b 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -47,7 +47,7 @@ void PlayerStats_GameReport_Reset_All() if(PS_GR_OUT_DB < 0) return; - for (int i = 0; i < 16; i++) + for (int i = 0; i < 16; ++i) if (teamscorekeepers[i]) PlayerStats_GameReport_AddTeam(i + 1); FOREACH_CLIENT(true, { diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 1bb77a1f5..d9a098691 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -239,7 +239,7 @@ string build_mutator_list(string s) n = tokenizebyseparator(s, ", "); } string s2 = ""; - for (string arg = ""; i < n; i++) + for (string arg = ""; i < n; ++i) { if (i >= 0) arg = argv(i); // cond is the condition for showing the mutator enabled in the menu diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index 9ca0b3192..4066efc4e 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -201,7 +201,7 @@ void W_RocketMinsta_Attack(entity actor, .entity weaponentity, int mode) // uses electro effects W_MuzzleFlash(WEP_ELECTRO, actor, weaponentity, w_shotorg, w_shotdir); - for (int counter = 0; counter < total; counter++) + for (int counter = 0; counter < total; ++counter) { proj = new(plasma_prim); proj.owner = proj.realowner = actor; diff --git a/qcsrc/ecs/systems/physics.qc b/qcsrc/ecs/systems/physics.qc index c7fc88dc9..a68faea44 100644 --- a/qcsrc/ecs/systems/physics.qc +++ b/qcsrc/ecs/systems/physics.qc @@ -437,7 +437,7 @@ void sys_phys_simulate_simple(entity this, float dt) this.angles += dt * this.avelocity; float movetime = dt; - for (int i = 0; i < MAX_CLIP_PLANES && movetime > 0; i++) { + for (int i = 0; i < MAX_CLIP_PLANES && movetime > 0; ++i) { vector push = vel * movetime; vector p0 = pos; vector p1 = p0 + push; diff --git a/qcsrc/lib/json.qc b/qcsrc/lib/json.qc index b477fe15e..c75dc8eec 100644 --- a/qcsrc/lib/json.qc +++ b/qcsrc/lib/json.qc @@ -76,7 +76,7 @@ bool _json_parse_array() { int len = bufstr_add(_json_buffer, "0", 0); if (len) bufstr_set(_json_buffer, len - 1, strcat(bufstr_get(_json_buffer, len - 1), ".length")); bool required = false; - for (int n = 0; ; n++) { + for (int n = 0; ; ++n) { string key = ftos(n); key = _json_ns ? strcat(_json_ns, ".", key) : key; int it = bufstr_add(_json_buffer, key, 0); diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 72673b235..743f4310b 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -570,7 +570,7 @@ vector checkColorCode(string theText, int text_len, int pos, bool check_at_the_e int ofs = cc_len; if (!check_at_the_end) ofs--; - for (; ofs >= 1; ofs--) + for (; ofs >= 1; --ofs) { if (!(pos >= ofs && text_len >= pos + (cc_len - ofs))) continue; diff --git a/qcsrc/menu/xonotic/maplist.qc b/qcsrc/menu/xonotic/maplist.qc index 81bf34e52..89748e85c 100644 --- a/qcsrc/menu/xonotic/maplist.qc +++ b/qcsrc/menu/xonotic/maplist.qc @@ -234,7 +234,7 @@ void MapList_Add_Shown(entity btn, entity me) { float i, n; n = strlen(me.g_maplistCache); - for (i = 0 ; i < n; i++) + for (i = 0 ; i < n; ++i) { if (!me.g_maplistCacheQuery(me, i)) me.g_maplistCacheToggle(me, i); @@ -246,7 +246,7 @@ void MapList_Remove_Shown(entity btn, entity me) { float i, n; n = strlen(me.g_maplistCache); - for (i = 0 ; i < n; i++) + for (i = 0 ; i < n; ++i) { if (me.g_maplistCacheQuery(me, i)) me.g_maplistCacheToggle(me, i); diff --git a/qcsrc/menu/xonotic/weaponarenacheckbox.qc b/qcsrc/menu/xonotic/weaponarenacheckbox.qc index 695b2d787..69839ec60 100644 --- a/qcsrc/menu/xonotic/weaponarenacheckbox.qc +++ b/qcsrc/menu/xonotic/weaponarenacheckbox.qc @@ -22,7 +22,7 @@ void XonoticWeaponarenaCheckBox_setChecked(entity me, float foo) void XonoticWeaponarenaCheckBox_loadCvars(entity me) { int n = tokenize_console(cvar_string("menu_weaponarena")); - for (int i = 0; i < n; i++) + for (int i = 0; i < n; ++i) { if(argv(i) == me.netname) { diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index 0d2ed77ac..2a557c5f0 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -170,7 +170,7 @@ void waypoint_getSymmetricalOrigin_cmd(entity caller, bool save, int arg_idx) { vector org = '0 0 0'; int ctf_flags = 0; - for (int i = 0; i < 6; i++) + for (int i = 0; i < 6; ++i) { if (argv(arg_idx + i) != "") ctf_flags++; @@ -190,7 +190,7 @@ void waypoint_getSymmetricalOrigin_cmd(entity caller, bool save, int arg_idx) else { vector v1, v2, v3, v4, v5, v6; - for (int i = 1; i <= ctf_flags; i++) + for (int i = 1; i <= ctf_flags; ++i) { if (i == 1) { v1 = stov(argv(arg_idx++)); org = v1 / ctf_flags; } else if (i == 2) { v2 = stov(argv(arg_idx++)); org += v2 / ctf_flags; } diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 820f88ebf..b0b68fd92 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -1275,7 +1275,7 @@ void setItemGroup(entity this) void setItemGroupCount() { - for (int k = 1; k <= group_count; k++) + for (int k = 1; k <= group_count; ++k) { int count = 0; IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; }); diff --git a/qcsrc/server/weapons/accuracy.qc b/qcsrc/server/weapons/accuracy.qc index 150d480ec..a09719f25 100644 --- a/qcsrc/server/weapons/accuracy.qc +++ b/qcsrc/server/weapons/accuracy.qc @@ -60,7 +60,7 @@ void accuracy_reset(entity e) entity a = CS(e).accuracy; if (!a) return; - for (int i = 0; i < REGISTRY_MAX(Weapons); i++) + for (int i = 0; i < REGISTRY_MAX(Weapons); ++i) { a.accuracy_frags[i] = 0; a.accuracy_hit[i] = 0; diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 926349a57..90ddd1a99 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -2433,7 +2433,7 @@ void RunThink(entity this, float dt) float oldtime = time; // do we need to save this? - for (int iterations = 0; iterations < 128 && !wasfreed(this); iterations++) + for (int iterations = 0; iterations < 128 && !wasfreed(this); ++iterations) { time = max(oldtime, this.nextthink); this.nextthink = 0;