From a94325afe437a50b90faa10de27e8d30384de080 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 19 Nov 2021 20:37:13 +0000 Subject: [PATCH] [MIRROR] Replacing more C-style for loops with the faster, traditional ones. [MDB IGNORE] (#9560) * Replacing more C-style for loops with the faster, traditional ones. (#62908) * Replacing more C-style for loops with the faster, traditional ones. Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> --- code/__HELPERS/_lists.dm | 14 +++++++------- code/__HELPERS/files.dm | 2 +- code/__HELPERS/icons.dm | 10 +++++----- code/__HELPERS/text.dm | 10 +++++----- code/_onclick/hud/alert.dm | 4 ++-- code/controllers/subsystem/lag_switch.dm | 6 +++--- code/controllers/subsystem/vote.dm | 4 ++-- code/datums/ai_laws.dm | 10 +++++----- code/datums/components/tackle.dm | 2 +- code/datums/martial/wrestling.dm | 16 ++++++++-------- .../dynamic/dynamic_rulesets_roundstart.dm | 2 +- code/game/machinery/autolathe.dm | 2 +- code/game/machinery/computer/arcade/arcade.dm | 2 +- .../machinery/computer/arcade/orion_event.dm | 2 +- code/game/machinery/computer/dna_console.dm | 2 +- code/game/machinery/slotmachine.dm | 6 +++--- .../objects/effects/decals/cleanable/aliens.dm | 2 +- .../objects/effects/decals/cleanable/robots.dm | 2 +- .../effects/effect_system/effects_smoke.dm | 2 +- code/game/objects/effects/spawners/gibspawner.dm | 4 ++-- code/game/objects/items/chrono_eraser.dm | 2 +- code/game/objects/items/devices/taperecorder.dm | 2 +- code/game/objects/items/extinguisher.dm | 2 +- code/game/objects/items/granters.dm | 2 +- code/game/objects/items/mail.dm | 4 ++-- code/modules/mining/abandoned_crates.dm | 4 ++-- 26 files changed, 60 insertions(+), 60 deletions(-) diff --git a/code/__HELPERS/_lists.dm b/code/__HELPERS/_lists.dm index e36e510d42d..433d38b1576 100644 --- a/code/__HELPERS/_lists.dm +++ b/code/__HELPERS/_lists.dm @@ -357,7 +357,7 @@ return inserted_list = inserted_list.Copy() - for(var/i = 1, i < inserted_list.len, ++i) + for(var/i in 1 to inserted_list.len - 1) inserted_list.Swap(i, rand(i, inserted_list.len)) return inserted_list @@ -367,7 +367,7 @@ if(!inserted_list) return - for(var/i = 1, i < inserted_list.len, ++i) + for(var/i in 1 to inserted_list.len - 1) inserted_list.Swap(i, rand(i, inserted_list.len)) ///Return a list with no duplicate entries @@ -410,7 +410,7 @@ if(islist(wordlist)) var/max = min(wordlist.len, 24) var/bit = 1 - for(var/i = 1, i <= max, i++) + for(var/i in 1 to max) if(bitfield & bit) return_list += wordlist[i] bit = bit << 1 @@ -471,7 +471,7 @@ return //no need to move from_index += len //we want to shift left instead of right - for(var/i = 0, i < distance, ++i) + for(var/i in 1 to distance) inserted_list.Insert(from_index, null) inserted_list.Swap(from_index, to_index) inserted_list.Cut(to_index, to_index + 1) @@ -479,7 +479,7 @@ if(from_index > to_index) from_index += len - for(var/i = 0, i < len, ++i) + for(var/i in 1 to len) inserted_list.Insert(to_index, null) inserted_list.Swap(from_index, to_index) inserted_list.Cut(from_index, from_index + 1) @@ -495,7 +495,7 @@ else from_index += len - for(var/i = 0, i < distance, ++i) + for(var/i in 1 to distance) inserted_list.Insert(from_index, null) inserted_list.Swap(from_index, to_index) inserted_list.Cut(to_index, to_index + 1) @@ -505,7 +505,7 @@ to_index = from_index from_index = a - for(var/i = 0, i < len, ++i) + for(var/i in 1 to len) inserted_list.Swap(from_index++, to_index++) ///replaces reverseList ~Carnie diff --git a/code/__HELPERS/files.dm b/code/__HELPERS/files.dm index 2a0bdc6a098..1b6aa31da28 100644 --- a/code/__HELPERS/files.dm +++ b/code/__HELPERS/files.dm @@ -15,7 +15,7 @@ GLOBAL_VAR_INIT(fileaccess_timer, 0) root = "[GLOB.log_directory]/" var/path = root - for(var/i=0, i= 0) @@ -657,7 +657,7 @@ GLOBAL_LIST_INIT(binary, list("0","1")) var/punctbuffer = "" var/cutoff = 0 lentext = length_char(buffer) - for(var/pos = 1, pos <= lentext, pos++) + for(var/pos in 1 to lentext) let = copytext_char(buffer, -pos, -pos + 1) if(!findtext(let, GLOB.is_punctuation)) //This won't handle things like Nyaaaa!~ but that's fine break diff --git a/code/_onclick/hud/alert.dm b/code/_onclick/hud/alert.dm index 80858133967..41674a53f39 100644 --- a/code/_onclick/hud/alert.dm +++ b/code/_onclick/hud/alert.dm @@ -788,10 +788,10 @@ so as to remain in compliance with the most up-to-date laws." return var/list/alerts = mymob.alerts if(!hud_shown) - for(var/i = 1, i <= alerts.len, i++) + for(var/i in 1 to alerts.len) screenmob.client.screen -= alerts[alerts[i]] return 1 - for(var/i = 1, i <= alerts.len, i++) + for(var/i in 1 to alerts.len) var/atom/movable/screen/alert/alert = alerts[alerts[i]] if(alert.icon_state == "template") alert.icon = ui_style diff --git a/code/controllers/subsystem/lag_switch.dm b/code/controllers/subsystem/lag_switch.dm index f8bbd13e297..4a2be78e908 100644 --- a/code/controllers/subsystem/lag_switch.dm +++ b/code/controllers/subsystem/lag_switch.dm @@ -17,7 +17,7 @@ SUBSYSTEM_DEF(lag_switch) var/slowmode_cooldown = 3 SECONDS /datum/controller/subsystem/lag_switch/Initialize(start_timeofday) - for(var/i = 1, i <= measures.len, i++) + for(var/i in 1 to measures.len) measures[i] = FALSE var/auto_switch_pop = CONFIG_GET(number/auto_lag_switch_pop) if(auto_switch_pop) @@ -124,10 +124,10 @@ SUBSYSTEM_DEF(lag_switch) message_admins("Lag Switch enabling automatic measures now.") log_admin("Lag Switch enabling automatic measures now.") veto_timer_id = null - for(var/i = 1, i <= auto_measures.len, i++) + for(var/i in 1 to auto_measures.len) set_measure(auto_measures[i], state) return TRUE - for(var/i = 1, i <= measures.len, i++) + for(var/i in 1 to measures.len) set_measure(i, state) return TRUE diff --git a/code/controllers/subsystem/vote.dm b/code/controllers/subsystem/vote.dm index 0ecaad692e0..b957a143c15 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -86,7 +86,7 @@ SUBSYSTEM_DEF(vote) text += "[question]" else text += "[capitalize(mode)] Vote" - for(var/i=1,i<=choices.len,i++) + for(var/i in 1 to choices) var/votes = choices[choices[i]] if(!votes) votes = 0 @@ -218,7 +218,7 @@ SUBSYSTEM_DEF(vote) question = stripped_input(usr,"What is the vote for?") if(!question) return FALSE - for(var/i=1,i<=10,i++) + for(var/i in 1 to 10) var/option = capitalize(stripped_input(usr,"Please enter an option or hit cancel to finish")) if(!option || mode || !usr.client) break diff --git a/code/datums/ai_laws.dm b/code/datums/ai_laws.dm index 1571074c11b..afdf5165d9e 100644 --- a/code/datums/ai_laws.dm +++ b/code/datums/ai_laws.dm @@ -285,7 +285,7 @@ if(inherent.len && (LAW_INHERENT in groups)) law_amount += inherent.len if(supplied.len && (LAW_SUPPLIED in groups)) - for(var/index = 1, index <= supplied.len, index++) + for(var/index in 1 to supplied.len) var/law = supplied[index] if(length(law) > 0) law_amount++ @@ -364,13 +364,13 @@ laws += law if(ion.len && (LAW_ION in groups)) - for(var/i = 1, i <= ion.len, i++) + for(var/i in 1 to ion.len) ion[i] = pick_n_take(laws) if(hacked.len && (LAW_HACKED in groups)) - for(var/i = 1, i <= hacked.len, i++) + for(var/i in 1 to hacked.len) hacked[i] = pick_n_take(laws) if(inherent.len && (LAW_INHERENT in groups)) - for(var/i = 1, i <= inherent.len, i++) + for(var/i in 1 to inherent.len) inherent[i] = pick_n_take(laws) if(supplied.len && (LAW_SUPPLIED in groups)) var/i = 1 @@ -389,7 +389,7 @@ inherent -= . return var/list/supplied_laws = list() - for(var/index = 1, index <= supplied.len, index++) + for(var/index in 1 to supplied.len) var/law = supplied[index] if(length(law) > 0) supplied_laws += index //storing the law number instead of the law diff --git a/code/datums/components/tackle.dm b/code/datums/components/tackle.dm index bb37aad7901..d7977276079 100644 --- a/code/datums/components/tackle.dm +++ b/code/datums/components/tackle.dm @@ -454,7 +454,7 @@ playsound(user, 'sound/effects/Glasshit.ogg', 140, TRUE) if(W.type in list(/obj/structure/window, /obj/structure/window/fulltile, /obj/structure/window/unanchored, /obj/structure/window/fulltile/unanchored)) // boring unreinforced windows - for(var/i = 0, i < speed, i++) + for(var/i in 1 to speed) var/obj/item/shard/shard = new /obj/item/shard(get_turf(user)) shard.embedding = list(embed_chance = 100, ignore_throwspeed_threshold = TRUE, impact_pain_mult=3, pain_chance=5) shard.updateEmbedding() diff --git a/code/datums/martial/wrestling.dm b/code/datums/martial/wrestling.dm index 910e68e5882..1ae413053f1 100644 --- a/code/datums/martial/wrestling.dm +++ b/code/datums/martial/wrestling.dm @@ -142,18 +142,18 @@ If you make a derivative work from this code, you must include this notification to_chat(A, span_danger("You start spinning around with [D]!")) A.emote("scream") - for (var/i = 0, i < 20, i++) + for (var/i in 1 to 20) var/delay = 5 switch (i) - if (17 to INFINITY) + if (18 to INFINITY) delay = 0.25 - if (14 to 16) + if (15 to 17) delay = 0.5 - if (9 to 13) + if (10 to 14) delay = 1 - if (5 to 8) + if (6 to 9) delay = 2 - if (0 to 4) + if (1 to 5) delay = 3 if (A && D) @@ -227,7 +227,7 @@ If you make a derivative work from this code, you must include this notification FlipAnimation() - for (var/i = 0, i < 3, i++) + for (var/i in 1 to 3) if (A && D) A.pixel_y += 3 D.pixel_y += 3 @@ -332,7 +332,7 @@ If you make a derivative work from this code, you must include this notification return var/turf/T = get_turf(A) if (T && isturf(T) && D && isturf(D.loc)) - for (var/i = 0, i < 4, i++) + for (var/i in 1 to 4) A.setDir(turn(A.dir, 90)) A.forceMove(D.loc) diff --git a/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm b/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm index 4bf9ba9e31b..77210cd4e1a 100644 --- a/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm +++ b/code/game/gamemodes/dynamic/dynamic_rulesets_roundstart.dm @@ -605,7 +605,7 @@ . = ..() var/carriers_to_make = max(round(mode.roundstart_pop_ready / players_per_carrier, 1), 1) - for(var/j = 0, j < carriers_to_make, j++) + for(var/j in 1 to carriers_to_make) if (!candidates.len) break var/mob/carrier = pick_n_take(candidates) diff --git a/code/game/machinery/autolathe.dm b/code/game/machinery/autolathe.dm index 35c0762ea38..af2da872dd9 100644 --- a/code/game/machinery/autolathe.dm +++ b/code/game/machinery/autolathe.dm @@ -314,7 +314,7 @@ N.update_appearance() N.autolathe_crafted(src) else - for(var/i=1, i<=multiplier, i++) + for(var/i in 1 to multiplier) var/obj/item/new_item = new being_built.build_path(A) new_item.autolathe_crafted(src) diff --git a/code/game/machinery/computer/arcade/arcade.dm b/code/game/machinery/computer/arcade/arcade.dm index 05dfe065080..f2bae1674a5 100644 --- a/code/game/machinery/computer/arcade/arcade.dm +++ b/code/game/machinery/computer/arcade/arcade.dm @@ -89,7 +89,7 @@ GLOBAL_LIST_INIT(arcade_prize_pool, list( span_notice("You hear a flurry of buttons being pressed.")) say("CODE ACTIVATED: EXTRA PRIZES.") prizes *= 2 - for(var/i = 0, i < prizes, i++) + for(var/i in 1 to prizes) SEND_SIGNAL(user, COMSIG_ADD_MOOD_EVENT, "arcade", /datum/mood_event/arcade) if(prob(0.0001)) //1 in a million new /obj/item/gun/energy/pulse/prize(src) diff --git a/code/game/machinery/computer/arcade/orion_event.dm b/code/game/machinery/computer/arcade/orion_event.dm index bc778feccc6..80e8a9acb1c 100644 --- a/code/game/machinery/computer/arcade/orion_event.dm +++ b/code/game/machinery/computer/arcade/orion_event.dm @@ -524,7 +524,7 @@ if(game.obj_flags & EMAGGED) game.say("WEEWOO! WEEWOO! Spaceport security en route!") playsound(game, 'sound/items/weeoo1.ogg', 100, FALSE) - for(var/i, i<=3, i++) + for(var/i in 1 to 3) var/mob/living/simple_animal/hostile/syndicate/ranged/smg/orion/spaceport_security = new(get_turf(src)) spaceport_security.GiveTarget(usr) game.fuel += fuel diff --git a/code/game/machinery/computer/dna_console.dm b/code/game/machinery/computer/dna_console.dm index 8ce9b1c7c9a..0b97690e678 100644 --- a/code/game/machinery/computer/dna_console.dm +++ b/code/game/machinery/computer/dna_console.dm @@ -1786,7 +1786,7 @@ // No code will ever null this list, we can safely Cut it. tgui_genetic_makeup.Cut() - for(var/i=1, i <= NUMBER_OF_BUFFERS, i++) + for(var/i in 1 to NUMBER_OF_BUFFERS) if(genetic_makeup_buffer[i]) tgui_genetic_makeup["[i]"] = genetic_makeup_buffer[i].Copy() else diff --git a/code/game/machinery/slotmachine.dm b/code/game/machinery/slotmachine.dm index 0988131a2f2..ad1aef979ef 100644 --- a/code/game/machinery/slotmachine.dm +++ b/code/game/machinery/slotmachine.dm @@ -46,7 +46,7 @@ INVOKE_ASYNC(src, .proc/toggle_reel_spin, TRUE)//The reels won't spin unless we activate them var/list/reel = reels[1] - for(var/i = 0, i < reel.len, i++) //Populate the reels. + for(var/i in 1 to reel.len) //Populate the reels. randomize_reels() INVOKE_ASYNC(src, .proc/toggle_reel_spin, FALSE) @@ -269,7 +269,7 @@ if(paymode == HOLOCHIP) new /obj/item/holochip(loc,JACKPOT) else - for(var/i = 0, i < 5, i++) + for(var/i in 1 to 5) cointype = pick(subtypesof(/obj/item/coin)) var/obj/item/coin/C = new cointype(loc) random_step(C, 2, 50) @@ -293,7 +293,7 @@ /obj/machinery/computer/slot_machine/proc/get_lines() var/amountthesame - for(var/i = 1, i <= 3, i++) + for(var/i in 1 to 3) var/inputtext = reels[1][i] + reels[2][i] + reels[3][i] + reels[4][i] + reels[5][i] for(var/symbol in symbols) var/j = 3 //The lowest value we have to check for. diff --git a/code/game/objects/effects/decals/cleanable/aliens.dm b/code/game/objects/effects/decals/cleanable/aliens.dm index 6b960cefb8b..bb7d9a7d1a4 100644 --- a/code/game/objects/effects/decals/cleanable/aliens.dm +++ b/code/game/objects/effects/decals/cleanable/aliens.dm @@ -34,7 +34,7 @@ /obj/effect/decal/cleanable/xenoblood/xgibs/proc/streak(list/directions, mapload=FALSE) set waitfor = FALSE var/direction = pick(directions) - for(var/i = 0, i < pick(1, 200; 2, 150; 3, 50; 4, 17; 50), i++) //the 3% chance of 50 steps is intentional and played for laughs. + for(var/i in 1 to pick(1, 200; 2, 150; 3, 50; 4, 17; 50)) //the 3% chance of 50 steps is intentional and played for laughs. if (!mapload) sleep(2) if(i > 0) diff --git a/code/game/objects/effects/decals/cleanable/robots.dm b/code/game/objects/effects/decals/cleanable/robots.dm index 9ad93af8741..70e8012093b 100644 --- a/code/game/objects/effects/decals/cleanable/robots.dm +++ b/code/game/objects/effects/decals/cleanable/robots.dm @@ -20,7 +20,7 @@ /obj/effect/decal/cleanable/robot_debris/proc/streak(list/directions, mapload=FALSE) set waitfor = FALSE var/direction = pick(directions) - for (var/i = 0, i < pick(1, 200; 2, 150; 3, 50; 4, 17; 50), i++) //the 3% chance of 50 steps is intentional and played for laughs. + for (var/i in 1 to pick(1, 200; 2, 150; 3, 50; 4, 17; 50)) //the 3% chance of 50 steps is intentional and played for laughs. if (!mapload) sleep(2) if (i > 0) diff --git a/code/game/objects/effects/effect_system/effects_smoke.dm b/code/game/objects/effects/effect_system/effects_smoke.dm index 543ebdbb28e..a69a082c18e 100644 --- a/code/game/objects/effects/effect_system/effects_smoke.dm +++ b/code/game/objects/effects/effect_system/effects_smoke.dm @@ -24,7 +24,7 @@ if(frames == 0) frames = 1 //We will just assume that by 0 frames, the coder meant "during one frame". var/step = alpha / frames - for(var/i = 0, i < frames, i++) + for(var/i in 1 to frames) alpha -= step if(alpha < 160) set_opacity(0) //if we were blocking view, we aren't now because we're fading out diff --git a/code/game/objects/effects/spawners/gibspawner.dm b/code/game/objects/effects/spawners/gibspawner.dm index e55ea14bae2..ffb3223ea17 100644 --- a/code/game/objects/effects/spawners/gibspawner.dm +++ b/code/game/objects/effects/spawners/gibspawner.dm @@ -42,9 +42,9 @@ dna_to_add = list("Non-human DNA" = random_blood_type()) //else, generate a random bloodtype for it. - for(var/i = 1, i<= gibtypes.len, i++) + for(var/i in 1 to gibtypes.len) if(gibamounts[i]) - for(var/j = 1, j<= gibamounts[i], j++) + for(var/j in 1 to gibamounts[i]) var/gibType = gibtypes[i] gib = new gibType(loc, diseases) diff --git a/code/game/objects/items/chrono_eraser.dm b/code/game/objects/items/chrono_eraser.dm index 2995be22df9..6728647f5f1 100644 --- a/code/game/objects/items/chrono_eraser.dm +++ b/code/game/objects/items/chrono_eraser.dm @@ -188,7 +188,7 @@ var/icon/mob_snapshot = getFlatIcon(target) var/icon/cached_icon = new() - for(var/i=1, i<=CHRONO_FRAME_COUNT, i++) + for(var/i in 1 to CHRONO_FRAME_COUNT) var/icon/removing_frame = icon('icons/obj/chronos.dmi', "erasing", SOUTH, i) var/icon/mob_icon = icon(mob_snapshot) mob_icon.Blend(removing_frame, ICON_MULTIPLY) diff --git a/code/game/objects/items/devices/taperecorder.dm b/code/game/objects/items/devices/taperecorder.dm index 116e22c02d8..956adecd59d 100644 --- a/code/game/objects/items/devices/taperecorder.dm +++ b/code/game/objects/items/devices/taperecorder.dm @@ -299,7 +299,7 @@ playsound(src, 'sound/items/taperecorder/taperecorder_print.ogg', 50, FALSE) var/obj/item/paper/P = new /obj/item/paper(get_turf(src)) var/t1 = "Transcript:

" - for(var/i = 1, mytape.storedinfo.len >= i, i++) + for(var/i in 1 to mytape.storedinfo.len) t1 += "[mytape.storedinfo[i]]
" P.info = t1 var/tapename = mytape.name diff --git a/code/game/objects/items/extinguisher.dm b/code/game/objects/items/extinguisher.dm index bd28a91e9df..fc0e57b8da5 100644 --- a/code/game/objects/items/extinguisher.dm +++ b/code/game/objects/items/extinguisher.dm @@ -197,7 +197,7 @@ the_targets.Add(T3,T4) var/list/water_particles=list() - for(var/a=0, a<5, a++) + for(var/a in 1 to 5) var/obj/effect/particle_effect/water/W = new /obj/effect/particle_effect/water(get_turf(src)) var/my_target = pick(the_targets) water_particles[W] = my_target diff --git a/code/game/objects/items/granters.dm b/code/game/objects/items/granters.dm index 711083c612d..a9b9b78015d 100644 --- a/code/game/objects/items/granters.dm +++ b/code/game/objects/items/granters.dm @@ -52,7 +52,7 @@ return FALSE on_reading_start(user) reading = TRUE - for(var/i=1, i<=pages_to_mastery, i++) + for(var/i in 1 to pages_to_mastery) if(!turn_page(user)) on_reading_stopped() reading = FALSE diff --git a/code/game/objects/items/mail.dm b/code/game/objects/items/mail.dm index fd94c8499bc..c967788e801 100644 --- a/code/game/objects/items/mail.dm +++ b/code/game/objects/items/mail.dm @@ -71,7 +71,7 @@ // Add some random stamps. if(stamped == TRUE) var/stamp_count = rand(1, stamp_max) - for(var/i = 1, i <= stamp_count, i++) + for(var/i in 1 to stamp_count) stamps += list("stamp_[rand(2, 6)]") update_icon() @@ -159,7 +159,7 @@ else goodies += job_goodies - for(var/iterator = 0, iterator < goodie_count, iterator++) + for(var/iterator in 1 to goodie_count) var/target_good = pick_weight(goodies) var/atom/movable/target_atom = new target_good(src) body.log_message("[key_name(body)] received [target_atom.name] in the mail ([target_good])", LOG_GAME) diff --git a/code/modules/mining/abandoned_crates.dm b/code/modules/mining/abandoned_crates.dm index 1e5ddc96086..86e878754b4 100644 --- a/code/modules/mining/abandoned_crates.dm +++ b/code/modules/mining/abandoned_crates.dm @@ -38,8 +38,8 @@ for(var/i = 1, i <= length_input, i += length(char)) //put the guess into a list char = input[i] sanitised += text2num(char) - for(var/i = 1, i <= length(sanitised) - 1, i++) //compare each digit in the guess to all those following it - for(var/j = i + 1, j <= length(sanitised), j++) + for(var/i in 1 to length(sanitised) - 1) //compare each digit in the guess to all those following it + for(var/j in i + 1 to length(sanitised)) if(sanitised[i] == sanitised[j]) sanitycheck = FALSE //if a digit is repeated, reject the input if(input == code)