Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#4158 closed defect (fixed)

Timer.js Cleanup

Reported by: Stan Owned by: Stan
Priority: Should Have Milestone: Alpha 22
Component: UI & Simulation Keywords: patch
Cc: elexis Patch:

Description

Some fixes with the timer.js file.

Passed the tests.

Attachments (1)

4158.diff (3.8 KB ) - added by Stan 7 years ago.
Replace the array by an object.

Download all attachments as: .zip

Change History (15)

comment:1 by Stan, 8 years ago

Cc: elexis added
Owner: set to Stan
Status: newassigned

comment:2 by Vladislav Belov, 8 years ago

The patch looks good, but expressions like timer[0], timer[5] looks like magic, what's about constants?

Last edited 8 years ago by Vladislav Belov (previous) (diff)

comment:3 by elexis, 8 years ago

You are right, at the time we were discussing this with Yves too. We were wondering a bit whether it would make a performance impact to use an array instead of an object. But likely won't as they are basically the same thing internally anyway. The keys are just few bytes longer.

comment:4 by elexis, 8 years ago

Keywords: rfc removed
Milestone: Alpha 21Backlog

Backlogging due to lack of progress (Use object keys instead of an array in the timer)

comment:5 by Vladislav Belov, 7 years ago

Any progress?

comment:6 by Stan, 7 years ago

Nope i totally missed the last comments

in reply to:  6 comment:7 by Vladislav Belov, 7 years ago

Replying to stanislas69:

Nope i totally missed the last comments

Will you be able to update the patch?

comment:8 by Stan, 7 years ago

I'll try. Unless you want to do it.

comment:9 by wraitii, 7 years ago

Re performance: it can take up to 1-2 ms to create the 2nd array currently. So not a big big impact in the grand scale of things, but would be nice to reduce.

by Stan, 7 years ago

Attachment: 4158.diff added

Replace the array by an object.

comment:10 by Vladislav Belov, 7 years ago

Thanks for the patch!

comment:11 by Stan, 7 years ago

Keywords: rfc added
Milestone: BacklogAlpha 22

comment:12 by elexis, 7 years ago

Resolution: fixed
Status: assignedclosed

In 18981:

Timer component cleanup. Patch by Stan, fixes #4158.

Use objects instead of arrays to achieve more readable code.
Use two for-of loops, a continue instead of an if-else pattern and remove an unneeded variable dt.

comment:13 by elexis, 7 years ago

Keywords: rfc removed
  • s/of the game, in integer/in
  • Moving L40 to L41
  • Removing unneeded variable lateness (since we have a comment mentioning that the second argument is the lateness) and stack
  • Adding few newlines. Removed whitespace in empty lines.
  • Using for (let [id, timer] of this.timers), see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
  • Using for (let id of run) instead of for (let i = 0; i < run.length; ++i). With the following code snipped we can verify that the loop still works identically (considering the last statement of that loop):
    let run = [1, 2];
    
    for (let id of run)
    {
    	warn(id);
    	if (run.indexOf(3) == -1)
    		run.push(3);
    }
    
  • Splitting error message to multiple lines
  • Removing self evident // Non-repeating time - delete it and following comments

Plus that what Vladislav said.

comment:14 by Stan, 7 years ago

Thanks for the additions =)

Note: See TracTickets for help on using tickets.