소스 검색

perf: 优化 setConfigValue 效率

RyanCW 6 달 전
부모
커밋
1b7377534c
1개의 변경된 파일9개의 추가작업 그리고 3개의 파일을 삭제
  1. 9 3
      mqttclient/RyanMqttClient.c

+ 9 - 3
mqttclient/RyanMqttClient.c

@@ -32,13 +32,19 @@ static uint16_t RyanMqttGetNextPacketId(RyanMqttClient_t *client)
 static RyanMqttError_e setConfigValue(char **dest, char const *const rest)
 {
 	RyanMqttAssert(NULL != dest && NULL != rest);
+	int32_t restStrLen = (int32_t)strlen(rest);
 
-	// if (0 == strcmp(*dest, rest))
-	//     return RyanMqttSuccessError;
+	if (NULL != *dest)
+	{
+		if (0 == strncmp(*dest, rest, restStrLen))
+		{
+			return RyanMqttSuccessError;
+		}
+	}
 
 	platformMemoryFree(*dest);
 
-	RyanMqttStringCopy(dest, (char *)rest, strlen(rest));
+	RyanMqttStringCopy(dest, (char *)rest, restStrLen);
 	if (NULL == *dest)
 	{
 		return RyanMqttFailedError;