From what I saw in the past, StackOverflow seems like programming problems, such as fast char for string execution problems that got dozens of answers, This is an optimization task: take a very simple function and see if you can come up with a more reasonable one way to do it.
I had a function that I would like to optimize again for some time, but I always find that my optimizations have some hole leading to an incorrect exit - a rare special case in which they fail. But, given this feature, I always thought that one should be able to do better than that.
The function accepts the input data stream (effectively random bits, in terms of entropy) and transfers it to the NAL block. This includes the placement of escape codes: any sequence of bytes 00 00 00, 00 00 01, 00 00 02 or 00 00 03 is replaced by 00 00 03 XX, where XX is the last byte of the original sequence. As you might guess, they only get about 1 for every 4 million bytes of input, given the chances of such a sequence - so it's a challenge when one is looking for a huge amount of data and does almost nothing for it , except in very rare cases. However, since "doing something" involves inserting bytes, this makes things a little more complicated. The current unoptimized code is as follows: C:
src and dst are pointers to byte arrays, and end is pointers to the end of the input.
int i_count = 0;
while( src < end )
{
if( i_count == 2 && *src <= 0x03 )
{
*dst++ = 0x03;
i_count = 0;
}
if( *src == 0 )
i_count++;
else
i_count = 0;
*dst++ = *src++;
}
The total input data sizes for this function range from approximately 1,000 to 1,000,000 bytes of data.
My initial ideas include a function that (somehow) quickly searches for input for situations where an exit code is required to avoid more complex logic in the vast majority of inputs where you do not need to place escape codes.