HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

IS this script slow?

05-13-2009, 01:07 PM#1
moyack
Hi:

I've been offline these days working with an extendable struct that controls the looping though structs elements. Some advantages are that it's elegant in presentation and I can assign to one timer the control of several types of structs. One example of its usage is the fix of this spell made by me, there I use one timer to control an array of data with 2 different structs types.

This is the looping controller struct:

Collapse JASS:
interface Updater
    method Update takes nothing returns nothing
endinterface

private struct indexer extends Updater
    static timer T = CreateTimer()
    static integer counter = 0
    static indexer array indexers
    integer i
    boolean on = true
    
    private method Update takes nothing returns nothing
        debug call DisplayTimedTextFromPlayer(GetLocalPlayer(), 0,0,2, "Dummy update function has been executed...")
    endmethod
    
    static method DoUpdate takes Updater U returns nothing
        call U.Update()
    endmethod
    
    method onDestroy takes nothing returns nothing
        set indexer.counter = indexer.counter - 1
        set indexer.indexers[indexer.counter].i = .i
        set indexer.indexers[.i] = indexer.indexers[indexer.counter]
        if indexer.counter < 1 then
            call PauseTimer(indexer.T)
        endif
        set .on = false
    endmethod
    
    private static method Loop takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i > indexer.counter
            call indexer.DoUpdate(indexer.indexers[i])
            set i = i + 1
        endloop
    endmethod
    
    static method create takes nothing returns indexer
        local indexer I = indexer.allocate()
        set I.i = indexer.counter
        set indexer.indexers[indexer.counter] = integer(I)
        set indexer.counter = indexer.counter + 1
        if indexer.counter == 1 then
            call TimerStart(indexer.T, dt, true, function indexer.Loop)
        endif
        return I
    endmethod
endstruct

But recently I've seen that using an interface slows the code terribly due the internal compilation as a trigger execute o each function call.

My question are:

- Is this implementation wrong for large amount of data loaded (looping 100 - 200 instances)
- Modules could be faster?
05-13-2009, 07:16 PM#2
Anitarf
Modules would be faster.