summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-09 20:20:24 +0800
committerruki <[email protected]>2025-11-09 20:20:24 +0800
commit1b8d7a8ef65e54bfd86d5cafbab9f197974b0c82 (patch)
tree34b6dfbd4d8c81fdf0bc2239c3612a24bea8f933
parent55ae4a3b86e51d80c77e631db7270c5e5a2af2fb (diff)
format if-else
-rw-r--r--core/src/xmake/engine_pool.c6
-rw-r--r--core/src/xmake/hash/md5.c9
-rw-r--r--core/src/xmake/hash/rand32.c3
-rw-r--r--core/src/xmake/hash/rand64.c3
-rw-r--r--core/src/xmake/hash/sha.c9
-rw-r--r--core/src/xmake/hash/xxhash.c21
6 files changed, 34 insertions, 17 deletions
diff --git a/core/src/xmake/engine_pool.c b/core/src/xmake/engine_pool.c
index cf039d11e..39bdb1339 100644
--- a/core/src/xmake/engine_pool.c
+++ b/core/src/xmake/engine_pool.c
@@ -53,8 +53,9 @@ static tb_handle_t xm_engine_pool_instance_init(tb_cpointer_t *ppriv) {
}
static tb_void_t xm_engine_pool_instance_exit(tb_handle_t engine_pool, tb_cpointer_t priv) {
- if (engine_pool)
+ if (engine_pool) {
xm_engine_pool_exit((xm_engine_pool_ref_t)engine_pool);
+ }
}
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -72,8 +73,9 @@ xm_engine_pool_ref_t xm_engine_pool_init() {
tb_void_t xm_engine_pool_exit(xm_engine_pool_ref_t engine_pool) {
if (engine_pool) {
tb_for_all(xm_engine_ref_t, engine, engine_pool) {
- if (engine)
+ if (engine) {
xm_engine_exit(engine);
+ }
}
tb_single_list_exit(engine_pool);
}
diff --git a/core/src/xmake/hash/md5.c b/core/src/xmake/hash/md5.c
index 3c871b063..d07c355e4 100644
--- a/core/src/xmake/hash/md5.c
+++ b/core/src/xmake/hash/md5.c
@@ -80,9 +80,10 @@ tb_int_t xm_hash_md5(lua_State *lua) {
// read data
tb_long_t real = tb_stream_read(stream, data, sizeof(data));
- if (real > 0)
+ if (real > 0) {
tb_md5_spak(&md5, data, real);
// no data? continue it
+ }
else if (!real) {
// wait
real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream));
@@ -92,8 +93,9 @@ tb_int_t xm_hash_md5(lua_State *lua) {
tb_assert_and_check_break(real & TB_STREAM_WAIT_READ);
}
// failed or end?
- else
+ else {
break;
+ }
}
// exit md5
@@ -112,7 +114,8 @@ tb_int_t xm_hash_md5(lua_State *lua) {
// exit stream
tb_stream_exit(stream);
}
- if (!ok)
+ if (!ok) {
lua_pushnil(lua);
+ }
return 1;
}
diff --git a/core/src/xmake/hash/rand32.c b/core/src/xmake/hash/rand32.c
index 844dd83e7..7f5286b8e 100644
--- a/core/src/xmake/hash/rand32.c
+++ b/core/src/xmake/hash/rand32.c
@@ -37,8 +37,9 @@ tb_int_t xm_hash_rand32(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
static tb_uint64_t s_seed = 0;
- if (!s_seed)
+ if (!s_seed) {
s_seed = (tb_uint64_t)tb_uclock();
+ }
s_seed = xm_hash_xorshift64(s_seed);
tb_char_t s[256];
diff --git a/core/src/xmake/hash/rand64.c b/core/src/xmake/hash/rand64.c
index 0f9e39069..ea9539ced 100644
--- a/core/src/xmake/hash/rand64.c
+++ b/core/src/xmake/hash/rand64.c
@@ -40,8 +40,9 @@ tb_int_t xm_hash_rand64(lua_State *lua) {
tb_byte_t b[8];
tb_uint64_t word;
} s_seed = { 0 };
- if (!s_seed.word)
+ if (!s_seed.word) {
s_seed.word = (tb_uint64_t)tb_uclock();
+ }
s_seed.word = xm_hash_xorshift64(s_seed.word);
tb_char_t s[256];
diff --git a/core/src/xmake/hash/sha.c b/core/src/xmake/hash/sha.c
index 158a09208..4fddb0b83 100644
--- a/core/src/xmake/hash/sha.c
+++ b/core/src/xmake/hash/sha.c
@@ -87,9 +87,10 @@ tb_int_t xm_hash_sha(lua_State *lua) {
// read data
tb_long_t real = tb_stream_read(stream, data, sizeof(data));
- if (real > 0)
+ if (real > 0) {
tb_sha_spak(&sha, data, real);
// no data? continue it
+ }
else if (!real) {
// wait
real = tb_stream_wait(stream, TB_STREAM_WAIT_READ, tb_stream_timeout(stream));
@@ -99,8 +100,9 @@ tb_int_t xm_hash_sha(lua_State *lua) {
tb_assert_and_check_break(real & TB_STREAM_WAIT_READ);
}
// failed or end?
- else
+ else {
break;
+ }
}
// exit sha
@@ -120,7 +122,8 @@ tb_int_t xm_hash_sha(lua_State *lua) {
// exit stream
tb_stream_exit(stream);
}
- if (!ok)
+ if (!ok) {
lua_pushnil(lua);
+ }
return 1;
}
diff --git a/core/src/xmake/hash/xxhash.c b/core/src/xmake/hash/xxhash.c
index 7a55ce63d..035ba4497 100644
--- a/core/src/xmake/hash/xxhash.c
+++ b/core/src/xmake/hash/xxhash.c
@@ -103,10 +103,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) {
XXH3_state_t *state = XM_XXH3_createState();
if (tb_stream_open(stream) && state) {
// reset xxhash
- if (mode == 32 || mode == 64)
+ if (mode == 32 || mode == 64) {
XM_XXH3_64bits_reset(state);
- else
+ }
+ else {
XM_XXH3_128bits_reset(state);
+ }
// read data and update xxhash
tb_byte_t data[TB_STREAM_BLOCK_MAXN];
@@ -115,10 +117,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) {
tb_long_t real = tb_stream_read(stream, data, sizeof(data));
if (real > 0) {
- if (mode == 32 || mode == 64)
+ if (mode == 32 || mode == 64) {
XM_XXH3_64bits_update(state, data, real);
- else
+ }
+ else {
XM_XXH3_128bits_update(state, data, real);
+ }
}
// no data? continue it
else if (!real) {
@@ -130,8 +134,9 @@ tb_int_t xm_hash_xxhash(lua_State *lua) {
tb_assert_and_check_break(real & TB_STREAM_WAIT_READ);
}
// failed or end?
- else
+ else {
break;
+ }
}
// compuate hash
@@ -165,10 +170,12 @@ tb_int_t xm_hash_xxhash(lua_State *lua) {
tb_stream_exit(stream);
// exit xxhash
- if (state)
+ if (state) {
XM_XXH3_freeState(state);
+ }
}
- if (!ok)
+ if (!ok) {
lua_pushnil(lua);
+ }
return 1;
}