Raised This Month: $ Target: $400
 0% 

Is this optimization?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
baneado
Veteran Member
Join Date: Dec 2012
Location: amxmodx-es.com
Old 02-03-2017 , 11:55   Is this optimization?
Reply With Quote #1

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?

Last edited by baneado; 02-03-2017 at 11:59.
baneado is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-03-2017 , 12:39   Re: Is this optimization?
Reply With Quote #2

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 
    
}

__________________
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-03-2017 , 13:01   Re: Is this optimization?
Reply With Quote #3

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.
__________________

Last edited by HamletEagle; 02-03-2017 at 13:02.
HamletEagle is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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