AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Is this optimization? (https://forums.alliedmods.net/showthread.php?t=293526)

baneado 02-03-2017 11:55

Is this optimization?
 
Well, look this please.

PHP Code:

//on plugin_init()
register_event("AmmoX""event_ammo_x""be")

public 
event_ammo_x(id)
{
    
// code....

    
static amountamount read_data(2)
    
    if (
amount 120// bp ammo
    
{
        
// do whatever 
    
}


I don't use "amount" anymore.

Is it optimization create a static to do that, or I just use read_data(2) without creating a static variable?

Why?

edon1337 02-03-2017 12:39

Re: Is this optimization?
 
Using 'new' is just fine. It's not like it's gonna be used a lot of times.
PHP Code:

//on plugin_init()
register_event("AmmoX""event_ammo_x""be")

public 
event_ammo_x(id)
{
    
// code....

    
new amount read_data(2)
    
    if (
amount 120// bp ammo
    
{
        
// do whatever 
    
}



HamletEagle 02-03-2017 13:01

Re: Is this optimization?
 
You should use new, not static there. Do how you like, use directly the native or save it in a variable, doesn't matter.
For the ones saying that he is creating a variable for nothing, please think about readability and also know that micro optimization does not worth.


All times are GMT -4. The time now is 20:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.