@@ -2947,14 +2947,9 @@ typedef enum {
2947
2947
MB_BOTH_TRIM = 3
2948
2948
} MB_TRIM_MODE ;
2949
2949
2950
- static bool is_trim_wchar (uint32_t w , uint32_t * characters , size_t characters_len )
2950
+ static bool is_trim_wchar (uint32_t w , HashTable * ht )
2951
2951
{
2952
- for (size_t i = 0 ; i < characters_len ; i ++ ) {
2953
- if (w == characters [i ]) {
2954
- return true;
2955
- }
2956
- }
2957
- return false;
2952
+ return zend_hash_index_exists (ht , w );
2958
2953
}
2959
2954
2960
2955
static zend_string * trim_each_wchar (zend_string * str , zend_string * what , MB_TRIM_MODE mode , const mbfl_encoding * enc )
@@ -2977,43 +2972,49 @@ static zend_string* trim_each_wchar(zend_string *str, zend_string *what, MB_TRIM
2977
2972
return zend_string_copy (str );
2978
2973
}
2979
2974
2975
+ HashTable what_ht ;
2976
+ zval val ;
2977
+ zend_hash_init (& what_ht , what_len , NULL , NULL , false);
2978
+
2979
+ while (what_len ) {
2980
+ what_out_len = enc -> to_wchar (& what_in , & what_len , what_wchar_buf , 128 , & state );
2981
+ ZEND_ASSERT (what_out_len <= 128 );
2982
+ for (size_t i = 0 ; i < what_out_len ; i ++ ) {
2983
+ zend_hash_index_add_new (& what_ht , what_wchar_buf [i ], & val );
2984
+ }
2985
+ }
2986
+
2980
2987
while (in_len ) {
2981
2988
out_len = enc -> to_wchar (& in , & in_len , wchar_buf , 128 , & state );
2982
2989
ZEND_ASSERT (out_len <= 128 );
2983
2990
total_len += out_len ;
2984
2991
2985
- while (what_len ) {
2986
- what_out_len = enc -> to_wchar (& what_in , & what_len , what_wchar_buf , 128 , & state );
2987
- ZEND_ASSERT (what_out_len <= 128 );
2988
-
2989
- if (first && (mode & MB_LTRIM )) {
2990
- for (size_t i = 0 ; i < out_len ; i ++ ) {
2991
- uint32_t w = wchar_buf [i ];
2992
- if (is_trim_wchar (w , what_wchar_buf , what_out_len )) {
2993
- left += 1 ;
2994
- } else {
2995
- first = false;
2996
- break ;
2997
- }
2992
+ if (first && (mode & MB_LTRIM )) {
2993
+ for (size_t i = 0 ; i < out_len ; i ++ ) {
2994
+ uint32_t w = wchar_buf [i ];
2995
+ if (is_trim_wchar (w , & what_ht )) {
2996
+ left += 1 ;
2997
+ } else {
2998
+ first = false;
2999
+ break ;
2998
3000
}
2999
3001
}
3002
+ }
3000
3003
3001
- if (mode & MB_RTRIM ) {
3002
- for (size_t j = 0 ; j < out_len ; j ++ ) {
3003
- uint32_t w = wchar_buf [j ];
3004
- if (is_trim_wchar (w , what_wchar_buf , what_out_len )) {
3005
- right -= 1 ;
3006
- } else {
3007
- right = 0 ;
3008
- }
3004
+ if (mode & MB_RTRIM ) {
3005
+ for (size_t j = 0 ; j < out_len ; j ++ ) {
3006
+ uint32_t w = wchar_buf [j ];
3007
+ if (is_trim_wchar (w , & what_ht )) {
3008
+ right -= 1 ;
3009
+ } else {
3010
+ right = 0 ;
3009
3011
}
3010
3012
}
3011
3013
}
3012
-
3013
- what_in -= ZSTR_LEN (what );
3014
- what_len = ZSTR_LEN (what );
3015
3014
}
3016
3015
3016
+ zend_hash_destroy (& what_ht );
3017
+
3017
3018
return mb_get_substr (str , left , total_len + (right - left ), enc );
3018
3019
}
3019
3020
0 commit comments