小编nwm*_*een的帖子

strlen性能实现

这是一个多功能问题:

  • 这与glibc strlen实现相比如何?
  • 有没有更好的方法来实现这一点和自动向量化.

随机填充垃圾,因为stackoverflow以某种方式比我更了解代码到汇总比率

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>

/* Todo: Document */
#define WORD_ONES_LOW   ((size_t)-1 / UCHAR_MAX)
#define WORD_ONES_HIGH  (((size_t)-1 / UCHAR_MAX) << (CHAR_BIT - 1))

/*@doc
 * @desc: see if an arch word has a zero
 * #param: w - string aligned to word size
 */
static inline bool word_has_zero(const size_t *w)
{
    return ((*w - WORD_ONES_LOW) & ~*w & WORD_ONES_HIGH);
}

/*@doc
 * @desc: see POSIX strlen() …
Run Code Online (Sandbox Code Playgroud)

c string performance strlen

8
推荐指数
1
解决办法
2381
查看次数

C块范围功能?

是否可以创建一个适用于块范围的函数?如

编辑澄清

enum { cannot, must };
int it(enum modal verb);

describe(fx) {
    context("some context") {
        it(must) { /* Some test that returns an int to it() */ };
    }
}
Run Code Online (Sandbox Code Playgroud)

我怀疑这是可能的,那么我能做的下一个最好的事情是什么?

c

3
推荐指数
1
解决办法
1021
查看次数

标签 统计

c ×2

performance ×1

string ×1

strlen ×1