@@ -50,7 +50,6 @@ static const size_t DEF_UTF16_BUF_SIZE = 1024;
50
50
/* {{{ collator_regular_compare_function */
51
51
static int collator_regular_compare_function (zval * result , zval * op1 , zval * op2 )
52
52
{
53
- Collator_object * co = NULL ;
54
53
int rc = SUCCESS ;
55
54
zval str1 , str2 ;
56
55
zval num1 , num2 ;
@@ -70,21 +69,10 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
70
69
( str1_p == ( num1_p = collator_convert_string_to_number_if_possible ( str1_p , & num1 ) ) ||
71
70
str2_p == ( num2_p = collator_convert_string_to_number_if_possible ( str2_p , & num2 ) ) ) )
72
71
{
73
- /* Fetch collator object. */
74
- co = Z_INTL_COLLATOR_P (& INTL_G (current_collator ));
75
-
76
- if (!co || !co -> ucoll ) {
77
- intl_error_set_code ( NULL , COLLATOR_ERROR_CODE ( co ) );
78
- intl_errors_set_custom_msg ( COLLATOR_ERROR_P ( co ),
79
- "Object not initialized" , 0 );
80
- zend_throw_error (NULL , "Object not initialized" );
81
- rc = FAILURE ;
82
- goto cleanup ;
83
- }
84
-
85
72
/* Compare the strings using ICU. */
73
+ ZEND_ASSERT (INTL_G (current_collator ) != NULL );
86
74
ZVAL_LONG (result , ucol_strcoll (
87
- co -> ucoll ,
75
+ INTL_G ( current_collator ) ,
88
76
INTL_Z_STRVAL_P (str1_p ), INTL_Z_STRLEN_P (str1_p ),
89
77
INTL_Z_STRVAL_P (str2_p ), INTL_Z_STRLEN_P (str2_p ) ));
90
78
}
@@ -129,7 +117,6 @@ static int collator_regular_compare_function(zval *result, zval *op1, zval *op2)
129
117
zval_ptr_dtor ( norm2_p );
130
118
}
131
119
132
- cleanup :
133
120
if ( num1_p )
134
121
zval_ptr_dtor ( num1_p );
135
122
@@ -182,19 +169,16 @@ static int collator_icu_compare_function(zval *result, zval *op1, zval *op2)
182
169
{
183
170
zval str1 , str2 ;
184
171
int rc = SUCCESS ;
185
- Collator_object * co = NULL ;
186
172
zval * str1_p = NULL ;
187
173
zval * str2_p = NULL ;
188
174
189
175
str1_p = collator_make_printable_zval ( op1 , & str1 );
190
176
str2_p = collator_make_printable_zval ( op2 , & str2 );
191
177
192
- /* Fetch collator object. */
193
- co = Z_INTL_COLLATOR_P (& INTL_G (current_collator ));
194
-
195
178
/* Compare the strings using ICU. */
179
+ ZEND_ASSERT (INTL_G (current_collator ) != NULL );
196
180
ZVAL_LONG (result , ucol_strcoll (
197
- co -> ucoll ,
181
+ INTL_G ( current_collator ) ,
198
182
INTL_Z_STRVAL_P (str1_p ), INTL_Z_STRLEN_P (str1_p ),
199
183
INTL_Z_STRVAL_P (str2_p ), INTL_Z_STRLEN_P (str2_p ) ));
200
184
@@ -276,7 +260,7 @@ static collator_compare_func_t collator_get_compare_function( const zend_long so
276
260
/* {{{ Common code shared by collator_sort() and collator_asort() API functions. */
277
261
static void collator_sort_internal ( int renumber , INTERNAL_FUNCTION_PARAMETERS )
278
262
{
279
- zval saved_collator ;
263
+ UCollator * saved_collator ;
280
264
zval * array = NULL ;
281
265
HashTable * hash = NULL ;
282
266
zend_long sort_flags = COLLATOR_SORT_REGULAR ;
@@ -293,6 +277,11 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
293
277
/* Fetch the object. */
294
278
COLLATOR_METHOD_FETCH_OBJECT ;
295
279
280
+ if (!co -> ucoll ) {
281
+ zend_throw_error (NULL , "Object not initialized" );
282
+ RETURN_THROWS ();
283
+ }
284
+
296
285
/* Set 'compare function' according to sort flags. */
297
286
INTL_G (compare_func ) = collator_get_compare_function ( sort_flags );
298
287
@@ -303,14 +292,14 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
303
292
COLLATOR_CHECK_STATUS ( co , "Error converting hash from UTF-8 to UTF-16" );
304
293
305
294
/* Save specified collator in the request-global (?) variable. */
306
- ZVAL_COPY_VALUE ( & saved_collator , & INTL_G ( current_collator ) );
307
- ZVAL_OBJ ( & INTL_G ( current_collator ), Z_OBJ_P ( object )) ;
295
+ saved_collator = INTL_G ( current_collator );
296
+ INTL_G ( current_collator ) = co -> ucoll ;
308
297
309
298
/* Sort specified array. */
310
299
zend_hash_sort (hash , collator_compare_func , renumber );
311
300
312
301
/* Restore saved collator. */
313
- ZVAL_COPY_VALUE ( & INTL_G ( current_collator ), & saved_collator ) ;
302
+ INTL_G ( current_collator ) = saved_collator ;
314
303
315
304
/* Convert strings in the specified array back to UTF-8. */
316
305
collator_convert_hash_from_utf16_to_utf8 ( hash , COLLATOR_ERROR_CODE_P ( co ) );
0 commit comments