Skip to content

Commit

Permalink
Optimize code, add code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 13, 2024
1 parent de6ae95 commit 619b835
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ext-src/swoole_thread_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int handle_array_key(zval *key, zend_ulong *idx) {
case IS_NULL:
return IS_NULL;
case IS_DOUBLE:
*idx = Z_DVAL_P(key);
*idx = zend_dval_to_lval_safe(Z_DVAL_P(key));
return IS_LONG;
case IS_FALSE:
*idx = 0;
Expand Down
11 changes: 9 additions & 2 deletions include/swoole_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@

#define SW_STRINGL(s) s->str, s->length
#define SW_STRINGS(s) s->str, s->size
// copy value
#define SW_STRINGCVL(s) s->str + s->offset, s->length - s->offset

#define SW_STRING_FORMAT(s, format, ...) s->length = sw_snprintf(SW_STRINGS(s), format, ##__VA_ARGS__)
// append value
#define SW_STRINGAVL(s) s->str + s->length, s->size - s->length
/**
* This function does not automatically expand memory;
* ensure that the value to be written is less than the actual remaining capacity (size-length).
* If the size of the value cannot be determined, should use the String::format() function.
*/
#define SW_STRING_FORMAT(s, format, ...) s->length += sw_snprintf(SW_STRINGAVL(s), format, ##__VA_ARGS__)

namespace swoole {

Expand Down

0 comments on commit 619b835

Please sign in to comment.