optimization

Test of 8 subsequent bytes isn't translated into a single compare instruction

我与影子孤独终老i 提交于 2020-08-27 22:14:09
问题 Motivated by this question, I compared three different functions for checking if 8 bytes pointed to by the argument are zeros (note that in the original question, characters are compared with '0' , not 0 ): bool f1(const char *ptr) { for (int i = 0; i < 8; i++) if (ptr[i]) return false; return true; } bool f2(const char *ptr) { bool res = true; for (int i = 0; i < 8; i++) res &= (ptr[i] == 0); return res; } bool f3(const char *ptr) { static const char tmp[8]{}; return !std::memcmp(ptr, tmp, 8

Test of 8 subsequent bytes isn't translated into a single compare instruction

白昼怎懂夜的黑 提交于 2020-08-27 22:12:57
问题 Motivated by this question, I compared three different functions for checking if 8 bytes pointed to by the argument are zeros (note that in the original question, characters are compared with '0' , not 0 ): bool f1(const char *ptr) { for (int i = 0; i < 8; i++) if (ptr[i]) return false; return true; } bool f2(const char *ptr) { bool res = true; for (int i = 0; i < 8; i++) res &= (ptr[i] == 0); return res; } bool f3(const char *ptr) { static const char tmp[8]{}; return !std::memcmp(ptr, tmp, 8

Test of 8 subsequent bytes isn't translated into a single compare instruction

喜你入骨 提交于 2020-08-27 22:12:26
问题 Motivated by this question, I compared three different functions for checking if 8 bytes pointed to by the argument are zeros (note that in the original question, characters are compared with '0' , not 0 ): bool f1(const char *ptr) { for (int i = 0; i < 8; i++) if (ptr[i]) return false; return true; } bool f2(const char *ptr) { bool res = true; for (int i = 0; i < 8; i++) res &= (ptr[i] == 0); return res; } bool f3(const char *ptr) { static const char tmp[8]{}; return !std::memcmp(ptr, tmp, 8

Test of 8 subsequent bytes isn't translated into a single compare instruction

久未见 提交于 2020-08-27 22:12:07
问题 Motivated by this question, I compared three different functions for checking if 8 bytes pointed to by the argument are zeros (note that in the original question, characters are compared with '0' , not 0 ): bool f1(const char *ptr) { for (int i = 0; i < 8; i++) if (ptr[i]) return false; return true; } bool f2(const char *ptr) { bool res = true; for (int i = 0; i < 8; i++) res &= (ptr[i] == 0); return res; } bool f3(const char *ptr) { static const char tmp[8]{}; return !std::memcmp(ptr, tmp, 8

Move the first four list items to the end of the list

徘徊边缘 提交于 2020-08-26 04:48:30
问题 So I have a list with several <li> elements, <ul> <li>a</li> <li>b</li> <li>c</li> <li>d</li> <li>e</li> <li>f</li> <li>g</li> <li>h</li> </ul> The context is I want to re-use li elements across a 1,000 memory intensive list for iOS. The objective is to display first 4 elements, the rest 4 are hidden, the container displays 4 items at a time. On scroll (button tap), I'm going to animate the list and slide in the other 4, and at the end of the animation, move the first 4 li items towards the