当我通读 glibc 源代码时,我在 strcat.c 中发现了这个有趣的注释。 任何人都可以解释这种优化是如何工作的吗?
/* Make S1 point before the next character, so we can increment
it while memory is read (wins on pipelined cpus). */
s1 -= 2;
do
{
c = *s2++;
*++s1 = c;
}
while (c != '\0');
最佳答案
流水线 CPU 可以并行执行某些操作。例如,它可以增加 S1 的地址,同时从它过去指向的地址读取。
关于c - 在读取内存时递增变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22089199/