Skip to content

Commit b05ad51

Browse files
committed
Don't redundantly flush mbstring filters multiple times
Each flush function in a chain of mbstring conversion filters always calls the next flush function in the chain. So it is not necessary to explicitly flush the second filter in a chain. (Due to this bug, in many cases, flush functions were actually being called three times.)
1 parent d1d50c2 commit b05ad51

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

ext/mbstring/libmbfl/mbfl/mbfilter.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ mbfl_buffer_converter_flush(mbfl_buffer_converter *convd)
234234
if (convd->filter1 != NULL) {
235235
mbfl_convert_filter_flush(convd->filter1);
236236
}
237-
if (convd->filter2 != NULL) {
238-
mbfl_convert_filter_flush(convd->filter2);
239-
}
240237

241238
return 0;
242239
}
@@ -262,9 +259,6 @@ mbfl_buffer_converter_feed_result(mbfl_buffer_converter *convd, mbfl_string *str
262259
if (convd->filter1 != NULL) {
263260
mbfl_convert_filter_flush(convd->filter1);
264261
}
265-
if (convd->filter2 != NULL) {
266-
mbfl_convert_filter_flush(convd->filter2);
267-
}
268262
result->encoding = convd->to;
269263
return mbfl_memory_device_result(&convd->device, result);
270264
}

ext/mbstring/libmbfl/mbfl/mbfl_convert.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ unsigned char* mbfl_convert_filter_feed_string(mbfl_convert_filter *filter, unsi
192192
int mbfl_convert_filter_flush(mbfl_convert_filter *filter)
193193
{
194194
(*filter->filter_flush)(filter);
195-
return filter->flush_function ? (*filter->flush_function)(filter->data) : 0;
195+
return 0;
196196
}
197197

198198
void mbfl_convert_filter_reset(mbfl_convert_filter *filter, const mbfl_encoding *from, const mbfl_encoding *to)
@@ -392,16 +392,12 @@ const struct mbfl_convert_vtbl* mbfl_convert_filter_get_vtbl(const mbfl_encoding
392392
*/
393393
void mbfl_filt_conv_common_ctor(mbfl_convert_filter *filter)
394394
{
395-
filter->status = 0;
396-
filter->cache = 0;
395+
filter->status = filter->cache = 0;
397396
}
398397

399398
int mbfl_filt_conv_common_flush(mbfl_convert_filter *filter)
400399
{
401-
filter->status = 0;
402-
filter->cache = 0;
403-
404-
if (filter->flush_function != NULL) {
400+
if (filter->flush_function) {
405401
(*filter->flush_function)(filter->data);
406402
}
407403
return 0;

0 commit comments

Comments
 (0)