[Tutorial] New Code Optimizations
#38

Quote:
Originally Posted by Yashas
View Post
Today I learned that the fact that PAWN arranges static/global data linearly can be 'abused'.

Code:
static hello[] = {''H','e','l','l','o'}, world[]={' ', 'W', 'o', 'r', 'l', 'd', '!', 0};
print(hello);
That will result in "Hello World!".

The main potential I see for this idea is you can avoid repeated addtiton of a constant to an array.

Code:
static str[144] = "123_";

while(pos < 100)
     str[pos + 3] = some_other_String[pos++];

print(str);
can be written as

Code:
static prefix[4] = {'1', '2', '3', '_'}, str[144];

while(pos < 100)
     str[pos] = some_other_String[pos++];

print(prefix); //will print the contents of str along with the contents of prefix since prefix is not null terminated.
Quote:
Originally Posted by Slice
View Post
Mind clarifying the last two examples? I don't get what you mean.
Quote:
Originally Posted by Yashas
View Post
Fixed a typo in the example. You can avoid the +3 and thats it!

Of course, its stupid to do such useless optimizations because it murders the readablity.

In the example, I try to copy a string to another string such that the destination string has a prefix "123_". In the first code, I had to add +3 while assigning the array element in every iteration so that the first 4 characters are skipped whereas in the second code doesn't need it at all. The example is just bad... strins would do it faster. I couldn't find a better example.

I now feel guilty for calling it "main potential".
This example given by Slice is much better.

Quote:
Originally Posted by Slice
View Post
Ah ok I see what you mean. This would be better then:
pawn Code:
static prefix[4] = {'1', '2', '3', '_'}, str[144];

str = some_other_String;

print(prefix);
Reply


Messages In This Thread
New Code Optimizations - by Yashas - 04.07.2015, 04:01
Re: New Code Optimizations - by Gammix - 04.07.2015, 09:59
Re: New Code Optimizations - by maximthepain - 04.07.2015, 10:33
Re: New Code Optimizations - by theYiin - 04.07.2015, 10:36
Re: New Code Optimizations - by Cypress - 04.07.2015, 10:42
Re: New Code Optimizations - by sammp - 04.07.2015, 10:51
Re: New Code Optimizations - by sammp - 04.07.2015, 10:59
Re: New Code Optimizations - by Gammix - 04.07.2015, 11:53
Re: New Code Optimizations - by Yashas - 04.07.2015, 15:49
Re: New Code Optimizations - by PT - 04.07.2015, 16:04
Re: New Code Optimizations - by Macluawn - 04.07.2015, 16:09
Re: New Code Optimizations - by Yashas - 04.07.2015, 16:17
Re: New Code Optimizations - by Gammix - 04.07.2015, 16:40
Re: New Code Optimizations - by Macluawn - 04.07.2015, 16:41
Re: New Code Optimizations - by Yashas - 04.07.2015, 16:53
Re: New Code Optimizations - by Macluawn - 04.07.2015, 16:56
Re: New Code Optimizations - by Yashas - 04.07.2015, 16:59
Re: New Code Optimizations - by Lynn - 04.07.2015, 17:17
Re: New Code Optimizations - by rymax99 - 04.07.2015, 17:52
Re: New Code Optimizations - by Gammix - 05.07.2015, 02:31
Re: New Code Optimizations - by Tamer - 05.07.2015, 19:50
Re: New Code Optimizations - by Stanford - 06.07.2015, 03:07
Re: New Code Optimizations - by Cypress - 06.07.2015, 20:31
Re: New Code Optimizations - by Yashas - 07.07.2015, 01:57
Re: New Code Optimizations - by Sime30 - 07.07.2015, 17:58
Re: New Code Optimizations - by kristo - 07.07.2015, 18:09
Re: New Code Optimizations - by Sime30 - 07.07.2015, 18:59
Re: New Code Optimizations - by JokeyL - 25.01.2016, 16:38
Re: New Code Optimizations - by iKarim - 25.01.2016, 16:45
Re: New Code Optimizations - by vannesenn - 16.06.2016, 23:38
Re: New Code Optimizations - by Crystallize - 16.06.2016, 23:43
Re: New Code Optimizations - by Gammix - 16.06.2016, 23:43
Re: New Code Optimizations - by Vince - 17.06.2016, 09:37
Re: New Code Optimizations - by Gammix - 17.06.2016, 10:02
Re: New Code Optimizations - by vannesenn - 17.06.2016, 14:38
Re: New Code Optimizations - by vannesenn - 17.06.2016, 21:23
Re: New Code Optimizations - by Yashas - 20.06.2016, 17:22
Re: New Code Optimizations - by Yashas - 21.07.2016, 13:23
Re: New Code Optimizations - by Kaperstone - 15.01.2018, 21:21
Re: New Code Optimizations - by Yashas - 31.01.2018, 17:42

Forum Jump:


Users browsing this thread: 2 Guest(s)