Take this code for example: https://play.crystal-lang.org/#/r/75ou
SuffixArray = ["i_atk_speed", "gfiuorhng", "ierojt", "20 more mods listed here in this array"]
PrefixArray = ["i_phys", "gfiuorhng", "ierojt", "20 more mods listed here in this array"]
GlobalModArray = SuffixArray + PrefixArray
def roll_mods()
mods_to_roll = SuffixArray + PrefixArray
pp mods_to_roll
end
roll_mods
Is there any performance difference between mods_to_roll
(creating a new local variable each time roll_mods
is called), and GlobalModArray
?
Using GlobalModArray
inside roll_mods is the correct way to do this, right? Unless I need mods_to_roll
to be mutable, correct?
If I use GlobalModArray
, I won’t have have to create a local variable and append both arrays. Since that was already done when the app started, that array is now in memory. Thus, it’s faster to access?