优化C ++中的字符数组成员交换

时间:2012-07-09 16:16:20

标签: c++

char buffer[256];

for(int x = 0; x<256; x+=4)
{
char one = buffer[x];
char two = buffer[x+1];
char three = buffer[x+2];
char four = buffer[x+3];

buffer[x] = four;
buffer[x+1]=three;
buffer[x+2]= two;
buffer[x+3]=one;
}

我究竟如何优化这个?

1 个答案:

答案 0 :(得分:5)

使用std::reverse

std::reverse(&buffer[x], &buffer[x + 4]);