File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -2713,10 +2713,15 @@ PHP_FUNCTION(mb_detect_encoding)
2713
2713
strict = MBSTRG (strict_detection );
2714
2714
}
2715
2715
2716
- mbfl_string_init (& string );
2717
- string .val = (unsigned char * )str ;
2718
- string .len = str_len ;
2719
- ret = mbfl_identify_encoding (& string , elist , size , strict );
2716
+ if (strict && size == 1 ) {
2717
+ /* If there is only a single candidate encoding, mb_check_encoding is faster */
2718
+ ret = (php_mb_check_encoding (str , str_len , * elist )) ? * elist : NULL ;
2719
+ } else {
2720
+ mbfl_string_init (& string );
2721
+ string .val = (unsigned char * )str ;
2722
+ string .len = str_len ;
2723
+ ret = mbfl_identify_encoding (& string , elist , size , strict );
2724
+ }
2720
2725
2721
2726
if (free_elist ) {
2722
2727
efree (ZEND_VOIDP (elist ));
You can’t perform that action at this time.
0 commit comments