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

feat: improve the performance of `strtolower` functions

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