提交 5ee1d059 编写于 作者: Z zhihaop

feat: improve the performance of `strtolower` functions

上级 1a3154df
......@@ -347,7 +347,6 @@ bool tscSupportAutoBatch(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd;
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd);
// only support insert statement.
if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_INSERT)) {
return false;
......
......@@ -225,66 +225,61 @@ char *tstrstr(char *src, char *dst, bool ignoreInEsc) {
}
char* strtolower(char *dst, const char *src) {
int esc = 0;
char quote = 0, *p = dst, c;
assert(dst != NULL);
for (c = *src++; c; c = *src++) {
if (esc) {
esc = 0;
} else if (quote) {
if (c == '\\') {
esc = 1;
} else if (c == quote) {
quote = 0;
if (src == NULL || dst == NULL) {
return dst;
}
char* const ret = dst;
while (*src) {
char ch = *(src++);
ch += (ch >= 'A' && ch <= 'Z') ? 'a' - 'A' : 0;
*(dst++) = ch;
if (ch == '\'' || ch == '"') {
char prev = ch;
while (*src) {
const char next = *(src++);
*(dst++) = next;
if (prev != '\\' && next == ch) break;
prev = next;
}
} else if (ch == '`') {
while (*src) {
const char next = *(src++);
*(dst++) = next;
if (next == ch) break;
}
} else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 'a';
} else if (c == '\'' || c == '"') {
quote = c;
}
*p++ = c;
}
*p = 0;
return dst;
*(dst) = 0;
return ret;
}
char* strntolower(char *dst, const char *src, int32_t n) {
int esc = 0, inEsc = 0;
char quote = 0, *p = dst, c;
assert(dst != NULL);
if (n == 0) {
*p = 0;
return dst;
}
for (c = *src++; n-- > 0; c = *src++) {
if (esc) {
esc = 0;
} else if (quote) {
if (c == '\\') {
esc = 1;
} else if (c == quote) {
quote = 0;
char* const end = dst + n;
while (dst != end) {
char ch = *(src++);
ch += (ch >= 'A' && ch <= 'Z') ? 'a' - 'A' : 0;
*(dst++) = ch;
if (ch == '\'' || ch == '"') {
char prev = ch;
while (dst != end) {
const char next = *(src++);
*(dst++) = next;
if (prev != '\\' && next == ch) break;
prev = next;
}
} else if (inEsc) {
if (c == '`') {
inEsc = 0;
} else if (ch == '`') {
while (dst != end) {
const char next = *(src++);
*(dst++) = next;
if (next == ch) break;
}
} else if (c >= 'A' && c <= 'Z') {
c -= 'A' - 'a';
} else if (inEsc == 0 && (c == '\'' || c == '"')) {
quote = c;
} else if (c == '`' && quote == 0) {
inEsc = 1;
}
*p++ = c;
}
*p = 0;
return dst;
*(dst) = 0;
return dst - n;
}
char* strntolower_s(char *dst, const char *src, int32_t n) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册