You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.
You can add some optimizations to all of FF2 code, i think.
These changes aren't so large but they can improve your code execution (i mean, execution speed).
It's just a little advice, you don't have to use it if you don't want to.
Applications
You can optimize string checks, string formats and reduce var usage (by freeing the variable from memory earlier than at the end of the function).
Code Snippet
You can replace Format functions with FormatEx wherever the output buffer is not used as the same input buffer.
Like:
Format( output, sizeof( output ), "%s", output ); // Don't replace this one because output buffer is the same input buffer
Format( output, sizeof( output ), "%s", input ); // You can replace this with FormatEx because input and output buffers aren't same strings (different variables)
FormatEx( output, sizeof( output ), "%s", input ); // This looks fine now
FormatEx( output, sizeof( output ), "%d %f", iMyVar, 35.0 ); // This looks fine too because output buffer is not used as the input buffer
This method can make your code faster a bit.
You can replace some string codes. if ( strlen( string ) ) can be replaced with if ( string[0] != 0 ) (or even if ( string[0] != '\0' ) if you use it to check that string isn't empty. strcopy( buffer, sizeof( buffer ), "" ); and Format( buffer, sizeof( buffer ), "" ); can be replaced with buffer[0] = 0 (or even buffer[0] = '\0') if you want to empty string.
These methods can make your code faster a bit too.
Last thing is that you can use code blocks without any condition (just to restrict local vars).
Vars that exist inside block will be freed at the block end.
So you can put some vars into separate blocks and these vars will exist only while block is executing. (they won't exist until the end of the whole function)
int Test() {
int iLocalVar = 0;
RunTest( iLocalVar );
AnotherTest1();
AnotherTest2();
<large code...>
}
can be replaced with:
int Test() {
{
int iLocalVar = 0; // Var exists only inside this block
RunTest( iLocalVar ); // Var will be freed from memory at the end of block
}
AnotherTest1();
AnotherTest2();
<large code...>
}
Other Information
There are some advanced mini-lessons about how SourcePawn works and described some hidden features. But ONLY in Russian! (you can use google translation or i can try to explain you something from those lessons) Here.
The text was updated successfully, but these errors were encountered:
Description
You can add some optimizations to all of FF2 code, i think.
These changes aren't so large but they can improve your code execution (i mean, execution speed).
It's just a little advice, you don't have to use it if you don't want to.
Applications
You can optimize string checks, string formats and reduce var usage (by freeing the variable from memory earlier than at the end of the function).
Code Snippet
Like:
This method can make your code faster a bit.
You can replace some string codes.
if ( strlen( string ) ) can be replaced with if ( string[0] != 0 ) (or even if ( string[0] != '\0' ) if you use it to check that string isn't empty.
strcopy( buffer, sizeof( buffer ), "" ); and Format( buffer, sizeof( buffer ), "" ); can be replaced with buffer[0] = 0 (or even buffer[0] = '\0') if you want to empty string.
These methods can make your code faster a bit too.
Last thing is that you can use code blocks without any condition (just to restrict local vars).
Vars that exist inside block will be freed at the block end.
So you can put some vars into separate blocks and these vars will exist only while block is executing. (they won't exist until the end of the whole function)
can be replaced with:
Other Information
There are some advanced mini-lessons about how SourcePawn works and described some hidden features. But ONLY in Russian! (you can use google translation or i can try to explain you something from those lessons)
Here.
The text was updated successfully, but these errors were encountered: