Raised This Month: $12 Target: $400
 3% 

Solved Little optimization


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-22-2020 , 10:02   Little optimization
Reply With Quote #1

Is there anyway that i can do this in just one line? I've been trying all different things but i can't seem to get it to work.

PHP Code:
if(get_pcvar_num(pSounds))
{
    
client_cmd(iAttacker"mp3 play %s"szSound);


This is something i'd use, but the last part "DO NOTHING" needs to be changed since it makes no sense
PHP Code:
(get_pcvar_num(pSounds) ? client_cmd(iAttacker"mp3 play %s"szSound) : client_cmd(iAttacker"DO NOTHING")); 
__________________

Last edited by Napoleon_be; 01-22-2020 at 11:41.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
JocAnis
Veteran Member
Join Date: Jun 2010
Old 01-22-2020 , 10:57   Re: Little optimization
Reply With Quote #2

your example in 'else' got me thinking of:
Code:
(get_pcvar_num(pSounds) ? client_cmd(iAttacker, "mp3 play %s", szSound))
but i get you meant other way...im also interested in this one line solution
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-22-2020 , 11:18   Re: Little optimization
Reply With Quote #3

Why in the world you want an one line solution?
How in the world would that be an optimization? Less lines has nothing to do with how fast the code is. You should try to write clear and readable code, not short code. Short code is not a goal, if the plugin ends up short that's cool, if it doesn't then it's perfectly fine.
Funny enough both the if check and the ternary operator would likely be translated to the same assembly instructions by the compiler.

Don't waste your time trying to fix something that's not broken.
__________________

Last edited by HamletEagle; 01-22-2020 at 11:19.
HamletEagle is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-22-2020 , 11:41   Re: Little optimization
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
Why in the world you want an one line solution?
How in the world would that be an optimization? Less lines has nothing to do with how fast the code is. You should try to write clear and readable code, not short code. Short code is not a goal, if the plugin ends up short that's cool, if it doesn't then it's perfectly fine.
Funny enough both the if check and the ternary operator would likely be translated to the same assembly instructions by the compiler.

Don't waste your time trying to fix something that's not broken.
Okay thanks
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Reply


Thread Tools
Display Modes

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 05:47.


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