Skip to content

Commit 3b5072f

Browse files
committedJan 3, 2023
Use smart_str in mb_http_input rather than mbfl_memory_device
For many years, the code has contained a TODO comment indicating that the original author had wanted to do this. Using smart_str makes the code shorter and cleaner, and it is another step towards removing a bunch of legacy mbstring code which will soon be unneeded.
1 parent 0e7160b commit 3b5072f

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed
 

‎ext/mbstring/mbstring.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
# include "php_mbregex.h"
6161
#endif
6262

63+
#include "zend_smart_str.h"
6364
#include "zend_multibyte.h"
6465
#include "mbstring_arginfo.h"
6566

@@ -1281,19 +1282,15 @@ PHP_FUNCTION(mb_http_input)
12811282
if (n == 0) {
12821283
RETURN_FALSE;
12831284
}
1284-
// TODO Use smart_str instead.
1285-
mbfl_string result;
1286-
mbfl_memory_device device;
1287-
mbfl_memory_device_init(&device, n * 12, 0);
1285+
1286+
smart_str result = {0};
12881287
for (size_t i = 0; i < n; i++, entry++) {
1289-
mbfl_memory_device_strcat(&device, (*entry)->name);
1290-
mbfl_memory_device_output(',', &device);
1288+
if (i > 0) {
1289+
smart_str_appendc(&result, ',');
1290+
}
1291+
smart_str_appends(&result, (*entry)->name);
12911292
}
1292-
mbfl_memory_device_unput(&device); /* Remove trailing comma */
1293-
mbfl_memory_device_result(&device, &result);
1294-
RETVAL_STRINGL((const char*)result.val, result.len);
1295-
mbfl_string_clear(&result);
1296-
return;
1293+
RETURN_STR(smart_str_extract(&result));
12971294
default:
12981295
zend_argument_value_error(1,
12991296
"must be one of \"G\", \"P\", \"C\", \"S\", \"I\", or \"L\"");

0 commit comments

Comments
 (0)
Please sign in to comment.