From e47cfab8bbabeeccd948ec9b421b03bd811d4bbb Mon Sep 17 00:00:00 2001 From: Gymee <8039110+Gymee@user.noreply.gitee.com> Date: Sat, 19 Sep 2020 13:16:35 +0800 Subject: [PATCH] tweak code for simplicity --- kv_store/src/kvstore_common/kvstore_common.c | 6 ++---- kv_store/src/kvstore_impl_hal/kv_store.c | 4 ++-- kv_store/src/kvstore_impl_posix/kv_store.c | 3 +-- timer_task/src/nativeapi_timer_task.c | 16 ++++++---------- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/kv_store/src/kvstore_common/kvstore_common.c b/kv_store/src/kvstore_common/kvstore_common.c index 2b713df..202591f 100755 --- a/kv_store/src/kvstore_common/kvstore_common.c +++ b/kv_store/src/kvstore_common/kvstore_common.c @@ -186,9 +186,7 @@ int ClearKVCacheInner(void) } g_itemHeader = NULL; g_itemTail = NULL; - if (g_sum != 0) { - return EC_FAILURE; - } - return EC_SUCCESS; + + return (g_sum != 0) ? EC_FAILURE : EC_SUCCESS; } #endif \ No newline at end of file diff --git a/kv_store/src/kvstore_impl_hal/kv_store.c b/kv_store/src/kvstore_impl_hal/kv_store.c index c1bec9a..3d4985b 100755 --- a/kv_store/src/kvstore_impl_hal/kv_store.c +++ b/kv_store/src/kvstore_impl_hal/kv_store.c @@ -140,8 +140,8 @@ int UtilsSetValue(const char* key, const char* value) currentNum++; } } - ret = SetCurrentItem(currentNum); - return ret; + + return SetCurrentItem(currentNum); } int UtilsDeleteValue(const char* key) diff --git a/kv_store/src/kvstore_impl_posix/kv_store.c b/kv_store/src/kvstore_impl_posix/kv_store.c index dfe9015..24bc57c 100755 --- a/kv_store/src/kvstore_impl_posix/kv_store.c +++ b/kv_store/src/kvstore_impl_posix/kv_store.c @@ -301,9 +301,8 @@ int UtilsDeleteValue(const char* key) #ifdef FEATURE_KV_CACHE int ClearKVCache(void) { - int ret; pthread_mutex_lock(&g_kvGlobalMutex); - ret = ClearKVCacheInner(); + int ret = ClearKVCacheInner(); pthread_mutex_unlock(&g_kvGlobalMutex); return ret; } diff --git a/timer_task/src/nativeapi_timer_task.c b/timer_task/src/nativeapi_timer_task.c index a47f3c8..1622d73 100755 --- a/timer_task/src/nativeapi_timer_task.c +++ b/timer_task/src/nativeapi_timer_task.c @@ -29,22 +29,19 @@ int StartTimerTask(bool isPeriodic, const unsigned int delay, void* userCallback if (userCallback == NULL) { return EC_FAILURE; } - KalTimerType timerType; - if (isPeriodic) { - timerType = KAL_TIMER_PERIODIC; - } else { - timerType = KAL_TIMER_ONCE; - } + + KalTimerType timerType = isPeriodic ? KAL_TIMER_PERIODIC : KAL_TIMER_ONCE; KalTimerId timerId = KalTimerCreate((KalTimerProc)userCallback, timerType, userContext, delay); if (timerId == NULL) { return EC_FAILURE; } - int ret = KalTimerStart(timerId); - if (ret != KAL_OK) { + + if (KalTimerStart(timerId) != KAL_OK) { StopTimerTask(timerId); return EC_FAILURE; } *timerHandle = timerId; + return EC_SUCCESS; } @@ -53,6 +50,5 @@ int StopTimerTask(const timerHandle_t timerHandle) if (timerHandle == NULL) { return EC_FAILURE; } - int ret = KalTimerDelete((KalTimerId)timerHandle); - return ret; + return KalTimerDelete((KalTimerId)timerHandle);; } \ No newline at end of file -- Gitee