[TD-6165]<enhance>: use memcpy to replace wcsncmp for nchar type comparision

This commit is contained in:
Ganlin Zhao 2021-08-17 17:04:10 +08:00
parent d1696b3862
commit 7e7b67146a
1 changed files with 2 additions and 21 deletions

View File

@ -129,16 +129,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
if (len1 != len2) { if (len1 != len2) {
return len1 > len2? 1:-1; return len1 > len2? 1:-1;
} else { } else {
char *pLeftTerm = (char *)tcalloc(len1 + 1, sizeof(char)); int32_t ret = memcmp((wchar_t*) pLeft, (wchar_t*) pRight, len1);
char *pRightTerm = (char *)tcalloc(len1 + 1, sizeof(char));
memcpy(pLeftTerm, varDataVal(pLeft), len1);
memcpy(pRightTerm, varDataVal(pRight), len2);
int32_t ret = wcsncmp((wchar_t*) pLeftTerm, (wchar_t*) pRightTerm, len1/TSDB_NCHAR_SIZE);
tfree(pLeftTerm);
tfree(pRightTerm);
if (ret == 0) { if (ret == 0) {
return 0; return 0;
} else { } else {
@ -418,17 +409,7 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
if (t1->len != t2->len) { if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1; return t1->len > t2->len? 1:-1;
} }
int32_t ret = memcmp((wchar_t*) t1, (wchar_t*) t2, t2->len);
char *t1_term = (char *)tcalloc(t1->len + 1, sizeof(char));
char *t2_term = (char *)tcalloc(t2->len + 1, sizeof(char));
memcpy(t1_term, t1->data, t1->len);
memcpy(t2_term, t2->data, t2->len);
int32_t ret = wcsncmp((wchar_t*) t1_term, (wchar_t*) t2_term, t2->len/TSDB_NCHAR_SIZE);
tfree(t1_term);
tfree(t2_term);
if (ret == 0) { if (ret == 0) {
return ret; return ret;
} }