1 #pragma once 2 #include "glib.h" 3 4 // 计算字符串的长度(经过测试,该版本比采用repne/scasb汇编的运行速度快16.8%左右) 5 static inline int strlen(const char *s) { 6 if (s == NULL) 7 return 0; 8 register int __res = 0; 9 while (s[__res] != '\0') { 10 ++__res; 11 } 12 return __res; 13 } 14 15 16 static inline int strcmp(const char *s1, const char *s2) { 17 while (*s1 && *s2 && *s1 == *s2) { 18 ++s1; 19 ++s2; 20 } 21 return *s1 - *s2; 22 }