سؤال

While I was reading through glibc source code, I found this interesting comment in strcat.c . Can anyone explain how does this optimization work?

/* 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');
هل كانت مفيدة؟

المحلول

Pipelined CPU's can do some things in parallel. For instance, it can increment the address of S1, while reading from the address it used to point at.

نصائح أخرى

It just means that the increment of s1 can be done while a char is being fetched from *s2, so it's free.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top