什么是最有效的方法来求xÿ连续值的数组?数组、方法来、最有效

2023-09-11 03:50:19 作者:左青龙右白虎

运行通过callgrind我的应用表明,这条线所绘一切由约10,000的一个因素。我可能会重新设计它周围,但它让我不知道;有没有更好的办法做到这一点?

Running my app through callgrind revealed that this line dwarfed everything else by a factor of about 10,000. I'm probably going to redesign around it, but it got me wondering; Is there a better way to do it?

下面是我在做什么的时刻:

Here's what I'm doing at the moment:

int i = 1;
while
(
    (
        (*(buffer++) == 0xffffffff && ++i) || 
        (i = 1)
    )
    &&
    i < desiredLength + 1
    &&
    buffer < bufferEnd
);

它寻找desiredLength为0xffffffff值的第一个块的一个32位无符号整型数组的偏移量。

It's looking for the offset of the first chunk of desiredLength 0xffffffff values in a 32 bit unsigned int array.

这是比任何实现我可以涉及内环拿出显著更快。但它仍然太他妈的慢。

It's significantly faster than any implementations I could come up with involving an inner loop. But it's still too damn slow.

推荐答案

您标记的c ++,所以我假定你有STL算法可供选择:

You tagged c++ so I assume you have STL algorithms available:

std::search_n(buffer, bufferEnd, desiredLength, 0xffffffff);