今天开始看Redis的源码,其中在最简单的数据结构SDS(Simple Dynamic String)的头文件中声明了以下的函数
static inline size_t sdslen(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
return sh->len;
}
看到这段代码楞了一下,之前一直以为inline这个关键词智能在C++中使用,没想到在这里也用到了....Google之。。。
http://stackoverflow.com/questions/7762731/whats-the-difference-between-static-and-static-inline-function
inline instructs the compiler to attempt to embed the function content into the calling code instead of executing an actual call.
For small functions that are called frequently that can make a big perform