@@ -24,11 +24,10 @@ END_EXTERN_C()
24
24
25
25
using namespace swoole;
26
26
27
- static inline void php_swoole_table_row2array (Table *table, TableRow *row, zval *return_value) {
27
+ static inline void php_swoole_table_row2array (const Table *table, TableRow *row, zval *return_value) {
28
28
array_init (return_value);
29
29
30
- for (auto i = table->column_list ->begin (); i != table->column_list ->end (); i++) {
31
- TableColumn *col = *i;
30
+ for (const auto col : *table->column_list ) {
32
31
if (col->type == TableColumn::TYPE_STRING) {
33
32
TableStringLength len = 0 ;
34
33
char *str = nullptr ;
@@ -48,9 +47,11 @@ static inline void php_swoole_table_row2array(Table *table, TableRow *row, zval
48
47
}
49
48
}
50
49
51
- static inline void php_swoole_table_get_field_value (
52
- Table *table, TableRow *row, zval *return_value, char *field, uint16_t field_len) {
53
- TableColumn *col = table->get_column (std::string (field, field_len));
50
+ static inline void php_swoole_table_get_field_value (Table *table,
51
+ TableRow *row,
52
+ zval *return_value,
53
+ const zend_string *field) {
54
+ TableColumn *col = table->get_column (std::string (ZSTR_VAL (field), ZSTR_LEN (field)));
54
55
if (!col) {
55
56
ZVAL_FALSE (return_value);
56
57
return ;
@@ -82,22 +83,22 @@ struct TableObject {
82
83
};
83
84
84
85
static inline TableObject *php_swoole_table_fetch_object (zend_object *obj) {
85
- return ( TableObject *) (( char *) obj - swoole_table_handlers.offset );
86
+ return reinterpret_cast < TableObject *>( reinterpret_cast < char *>( obj) - swoole_table_handlers.offset );
86
87
}
87
88
88
- static inline Table *php_swoole_table_get_ptr (zval *zobject) {
89
+ static inline Table *php_swoole_table_get_ptr (const zval *zobject) {
89
90
return php_swoole_table_fetch_object (Z_OBJ_P (zobject))->ptr ;
90
91
}
91
92
92
- static inline Table *php_swoole_table_get_and_check_ptr (zval *zobject) {
93
+ static inline Table *php_swoole_table_get_and_check_ptr (const zval *zobject) {
93
94
Table *table = php_swoole_table_get_ptr (zobject);
94
95
if (UNEXPECTED (!table)) {
95
96
swoole_fatal_error (SW_ERROR_WRONG_OPERATION, " must call constructor first" );
96
97
}
97
98
return table;
98
99
}
99
100
100
- static inline Table *php_swoole_table_get_and_check_ptr2 (zval *zobject) {
101
+ static inline Table *php_swoole_table_get_and_check_ptr2 (const zval *zobject) {
101
102
Table *table = php_swoole_table_get_and_check_ptr (zobject);
102
103
if (!table->ready ()) {
103
104
php_swoole_fatal_error (E_ERROR, " table is not created or has been destroyed" );
@@ -114,7 +115,7 @@ static inline void php_swoole_table_free_object(zend_object *object) {
114
115
}
115
116
116
117
static inline zend_object *php_swoole_table_create_object (zend_class_entry *ce) {
117
- TableObject *table = ( TableObject *) zend_object_alloc (sizeof (TableObject), ce);
118
+ auto *table = static_cast < TableObject *>( zend_object_alloc (sizeof (TableObject), ce) );
118
119
zend_object_std_init (&table->std , ce);
119
120
object_properties_init (&table->std , ce);
120
121
table->std .handlers = &swoole_table_handlers;
@@ -197,7 +198,7 @@ void php_swoole_table_minit(int module_number) {
197
198
PHP_METHOD (swoole_table, __construct) {
198
199
Table *table = php_swoole_table_get_ptr (ZEND_THIS);
199
200
if (table) {
200
- zend_throw_error (NULL , " Constructor of %s can only be called once" , SW_Z_OBJCE_NAME_VAL_P (ZEND_THIS));
201
+ zend_throw_error (nullptr , " Constructor of %s can only be called once" , SW_Z_OBJCE_NAME_VAL_P (ZEND_THIS));
201
202
RETURN_FALSE;
202
203
}
203
204
@@ -242,7 +243,7 @@ PHP_METHOD(swoole_table, column) {
242
243
php_swoole_fatal_error (E_WARNING, " unable to add column after table has been created" );
243
244
RETURN_FALSE;
244
245
}
245
- RETURN_BOOL (table->add_column (std::string (name, len), ( enum TableColumn::Type) type, size));
246
+ RETURN_BOOL (table->add_column (std::string (name, len), static_cast < TableColumn::Type>( type) , size));
246
247
}
247
248
248
249
static PHP_METHOD (swoole_table, create) {
@@ -298,8 +299,7 @@ static PHP_METHOD(swoole_table, set) {
298
299
HashTable *ht = Z_ARRVAL_P (array);
299
300
300
301
if (out_flags & SW_TABLE_FLAG_NEW_ROW) {
301
- for (auto i = table->column_list ->begin (); i != table->column_list ->end (); i++) {
302
- TableColumn *col = *i;
302
+ for (const auto col : *table->column_list ) {
303
303
zval *zv = zend_hash_str_find (ht, col->name .c_str (), col->name .length ());
304
304
if (zv == nullptr || ZVAL_IS_NULL (zv)) {
305
305
col->clear (row);
@@ -472,21 +472,20 @@ static PHP_METHOD(swoole_table, get) {
472
472
Table *table = php_swoole_table_get_and_check_ptr2 (ZEND_THIS);
473
473
char *key;
474
474
size_t keylen;
475
- char *field = nullptr ;
476
- size_t field_len = 0 ;
475
+ zend_string *field = nullptr ;
477
476
478
477
ZEND_PARSE_PARAMETERS_START_EX (ZEND_PARSE_PARAMS_THROW, 1 , 2 )
479
478
Z_PARAM_STRING (key, keylen)
480
479
Z_PARAM_OPTIONAL
481
- Z_PARAM_STRING (field, field_len )
480
+ Z_PARAM_STR_OR_NULL (field)
482
481
ZEND_PARSE_PARAMETERS_END_EX (RETURN_FALSE);
483
482
484
483
TableRow *_rowlock = nullptr ;
485
484
TableRow *row = table->get (key, keylen, &_rowlock);
486
485
if (!row) {
487
486
RETVAL_FALSE;
488
- } else if (field && field_len > 0 ) {
489
- php_swoole_table_get_field_value (table, row, return_value, field, ( uint16_t ) field_len );
487
+ } else if (field) {
488
+ php_swoole_table_get_field_value (table, row, return_value, field);
490
489
} else {
491
490
php_swoole_table_row2array (table, row, return_value);
492
491
}
0 commit comments