提交 3d55b9b2 编写于 作者: H haotuo

Optimize getenv performance by using self str cmp implementation

Issue: #I73MBP

Test: libc test & benchmark test
Signed-off-by: Nhaotuo <haotuo@huawei.com>
Change-Id: Ibf8667e46c5199e5b7c3039029efb5b9daacc836
上级 4ae0212f
......@@ -2180,6 +2180,7 @@ musl_src_porting_file = [
"src/sigchain/sigchain.c",
"src/conf/legacy.c",
"src/conf/sysconf.c",
"src/env/getenv.c",
]
musl_inc_hook_files = [
......
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *getenv(const char *name)
{
if (name == NULL || __environ == NULL)
return 0;
size_t i, l = 0;
const char *np;
char **p, *ep;
for (; *(name + l) && *(name + l) != '='; ++l);
for (p = __environ; (ep = *p) != NULL; ++p) {
for (np = name, i = l; i && *ep; i--) {
if (*ep++ != *np++) {
break;
}
}
if (i == 0 && *ep++ == '=') {
return (ep);
}
}
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册