HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Which one is better?

05-21-2009, 05:08 PM#1
TheWye
Hi, guys, I just want to ask something. Between the two triggers below, which one will be faster? (& cleaner?) :
Collapse JASS:
globals
    group global_G = CreateGroup()
endglobals

function test2 takes nothing returns nothing
    local unit U
    
    call GroupEnumUnitsInRange(global_G, GetRectCenterX(gg_rct_testrect), GetRectCenterY(gg_rct_testrect), 100.0, somefilter)
    loop
        set U = FirstOfGroup(global_G)
        exitwhen(U == null)
        //actions with the unit
    endloop
endfunction

function test1 takes nothing returns nothing 
    call TimerStart(CreateTimer(), 0.01, true, function test2)
endfunction

or this one :

Collapse JASS:
function test2 takes nothing returns nothing
    local unit U
    local group local_G = CreateGroup()
    
    call GroupEnumUnitsInRange(local_G, GetRectCenterX(gg_rct_testrect), GetRectCenterY(gg_rct_testrect), 100.0, somefilter)
    loop
        set U = FirstOfGroup(local_G)
        exitwhen(U == null)
        //actions with the unit
    endloop
    
    call DestroyGroup(G)
endfunction

function test1 takes nothing returns nothing 
    call TimerStart(CreateTimer(), 0.01, true, function test2)
endfunction

Actually, the main question is - is it better to create a local group over and over again everytime you want to use it and destroy it after you finish OR create a global group once and just keep filling units into it and emptying them after use? And if I'm not wrong, after the loop, the unit group will be empty, correct?
05-21-2009, 05:12 PM#2
0zyx0
You should use Group Utils. That would be the fastest and best way. Also, remember to set the local group variable to null.
05-21-2009, 05:13 PM#3
grim001
It's better to keep a global group. And yes, the group will wind up empty.
05-21-2009, 05:36 PM#4
TheWye
Allright. Thanks guys ;)
05-21-2009, 06:19 PM#5
Themerion
Looping with loop is slower than using the filter function for actions.

Collapse JASS:
function Filter takes nothing returns boolean
    if UnitIsAliveAndSpellTargetAndThatSortOfStuff( GetFilterUnit() ) then
    // Do actions with GetFilterUnit()
    return false
endfunction

boolexpr BE = Condition(function Filter)
call GroupEnumBlah(emptyGroup,somestuff, BE )