Raised This Month: $ Target: $400
 0% 

Checking pcvar/cvar - what method is fastest / best


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mordi
Senior Member
Join Date: Jul 2007
Location: o rly?
Old 09-30-2007 , 10:36   Checking pcvar/cvar - what method is fastest / best
Reply With Quote #1

When checking for a pcvar or a cvar in the start of a function, should i use:

Code:
public function() 
{
    if(get_pcvar_num(pcvar))
    {
        something
    }
}


or...

Code:
public fuction()
{
    if(!get_pcvar_num(pcvar))
        return PLUGIN_HANDLED
        
    something
    
}
What is the most efficient way?
__________________
Quote:
Originally Posted by Alka View Post
engine ?! 0o... *barf*

Last edited by mordi; 09-30-2007 at 10:38.
mordi is offline
Old 09-30-2007, 11:30
vl@d
This message has been deleted by Emp`.
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 09-30-2007 , 11:33   Re: Checking pcvar/cvar - what method is fastest / best
Reply With Quote #2

I agree with Will Shipley.

Quote:
What you should really do is write "if" statements that check for improper conditions, and if you find them, bail. This cleans your code immensely, in two important ways: (a) the main, normal execution path is all at the top level, so if the programmer is just trying to get a feel for the routine, all she needs to read is the top level statements, instead of trying to trace through indention levels figuring out what the "normal" case is, and (b) it puts the "bail" code right next to the correctness check, which is good because the "bail" code is usually very short and belongs with the correctness check.
The performance difference will be negligible to say the least. It might be worth noting that you only need to return a value if it's actually going to be used.

Most importantly, ignore vl@d.

Last edited by Lee; 09-30-2007 at 11:37.
Lee is offline
mordi
Senior Member
Join Date: Jul 2007
Location: o rly?
Old 09-30-2007 , 12:23   Re: Checking pcvar/cvar - what method is fastest / best
Reply With Quote #3

Thanks Lee!
I'll use this then:
Code:
public fuction()
{
    if(!get_pcvar_num(pcvar))
        return PLUGIN_HANDLED
        
    something
    
}
__________________
Quote:
Originally Posted by Alka View Post
engine ?! 0o... *barf*
mordi is offline
Old 09-30-2007, 13:36
X-Script
This message has been deleted by Emp`.
Old 09-30-2007, 14:32
mordi
This message has been deleted by mordi. Reason: my bad
Old 09-30-2007, 14:33
mordi
This message has been deleted by Emp`.
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 16:39.


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