@@ -249,7 +249,7 @@ _prepare_elem(const gchar *new_elem_name, XmlElemContext *last_elem_context, gbo
249
249
FilterXObject * new_elem_obj = _create_object_for_new_elem (last_elem_context -> current_obj , has_attrs , & new_elem_repr );
250
250
xml_elem_context_init (new_elem_context , last_elem_context -> current_obj , new_elem_obj );
251
251
252
- FilterXObject * new_elem_key = filterx_string_new ( new_elem_name , -1 );
252
+ FILTERX_STRING_DECLARE_ON_STACK ( new_elem_key , new_elem_name , -1 );
253
253
FilterXObject * existing_obj = NULL ;
254
254
255
255
if (!filterx_object_is_key_set (new_elem_context -> parent_obj , new_elem_key ))
@@ -314,8 +314,8 @@ _collect_attrs(const gchar *element_name, XmlElemContext *elem_context,
314
314
315
315
const gchar * attr_value = attribute_values [i ];
316
316
317
- FilterXObject * key = filterx_string_new ( attr_key -> str , attr_key -> len );
318
- FilterXObject * value = filterx_string_new ( attr_value , -1 );
317
+ FILTERX_STRING_DECLARE_ON_STACK ( key , attr_key -> str , attr_key -> len );
318
+ FILTERX_STRING_DECLARE_ON_STACK ( value , attr_value , -1 );
319
319
320
320
gboolean success = filterx_object_set_subscript (elem_context -> current_obj , key , & value );
321
321
@@ -336,7 +336,7 @@ static gboolean
336
336
_convert_to_dict (GMarkupParseContext * context , XmlElemContext * elem_context , GError * * error )
337
337
{
338
338
const gchar * parent_elem_name = (const gchar * ) g_markup_parse_context_get_element_stack (context )-> next -> data ;
339
- FilterXObject * key = filterx_string_new ( parent_elem_name , -1 );
339
+ FILTERX_STRING_DECLARE_ON_STACK ( key , parent_elem_name , -1 );
340
340
341
341
FilterXObject * dict_obj = filterx_object_create_dict (elem_context -> parent_obj );
342
342
if (!dict_obj )
@@ -349,7 +349,7 @@ _convert_to_dict(GMarkupParseContext *context, XmlElemContext *elem_context, GEr
349
349
350
350
if (existing_value_len > 0 )
351
351
{
352
- FilterXObject * existing_value_key = filterx_string_new ( "#text" , 5 );
352
+ FILTERX_STRING_DECLARE_ON_STACK ( existing_value_key , "#text" , 5 );
353
353
gboolean success = filterx_object_set_subscript (dict_obj , existing_value_key , & elem_context -> current_obj );
354
354
filterx_object_unref (existing_value_key );
355
355
@@ -447,12 +447,12 @@ static void
447
447
_replace_string_text (XmlElemContext * elem_context , const gchar * element_name , const gchar * text , gsize text_len ,
448
448
GError * * error )
449
449
{
450
- FilterXObject * text_obj = filterx_string_new ( text , text_len );
450
+ FILTERX_STRING_DECLARE_ON_STACK ( text_obj , text , text_len );
451
451
452
452
FilterXObject * parent_obj = filterx_ref_unwrap_rw (elem_context -> parent_obj );
453
453
if (filterx_object_is_type (parent_obj , & FILTERX_TYPE_NAME (dict )))
454
454
{
455
- FilterXObject * key = filterx_string_new ( element_name , -1 );
455
+ FILTERX_STRING_DECLARE_ON_STACK ( key , element_name , -1 );
456
456
gboolean result = filterx_object_set_subscript (parent_obj , key , & text_obj );
457
457
filterx_object_unref (key );
458
458
@@ -482,10 +482,10 @@ _replace_string_text(XmlElemContext *elem_context, const gchar *element_name, co
482
482
filterx_object_unref (text_obj );
483
483
}
484
484
485
- static FilterXObject *
486
- _create_text_obj (FilterXObject * dict , FilterXObject * existing_text_key , const gchar * text , gsize text_len )
485
+ static GString *
486
+ _concatenate_text_value (FilterXObject * dict , FilterXObject * existing_text_key , const gchar * text , gsize text_len )
487
487
{
488
- FilterXObject * text_obj = NULL ;
488
+ GString * buffer = NULL ;
489
489
490
490
FilterXObject * existing_obj = filterx_object_get_subscript (dict , existing_text_key );
491
491
if (existing_obj )
@@ -499,32 +499,26 @@ _create_text_obj(FilterXObject *dict, FilterXObject *existing_text_key, const gc
499
499
}
500
500
else if (existing_value_len )
501
501
{
502
- ScratchBuffersMarker marker ;
503
- GString * buffer = scratch_buffers_alloc_and_mark (& marker );
502
+ buffer = scratch_buffers_alloc ();
504
503
g_string_append_len (buffer , existing_value , existing_value_len );
505
504
g_string_append_len (buffer , text , text_len );
506
- text_obj = filterx_string_new (buffer -> str , buffer -> len );
507
- scratch_buffers_reclaim_marked (marker );
508
505
}
509
506
filterx_object_unref (existing_obj );
510
507
}
511
508
512
- if (!text_obj )
513
- text_obj = filterx_string_new (text , text_len );
514
-
515
- return text_obj ;
509
+ return buffer ;
516
510
}
517
511
518
512
static void
519
513
_add_text_to_dict (XmlElemContext * elem_context , const gchar * text , gsize text_len , GError * * error )
520
514
{
521
- FilterXObject * key = filterx_string_new ("#text" , 5 );
522
- FilterXObject * text_obj = _create_text_obj (elem_context -> current_obj , key , text , text_len );
515
+ FILTERX_STRING_DECLARE_ON_STACK (key , "#text" , 5 );
516
+ GString * new_text = _concatenate_text_value (elem_context -> current_obj , key , text , text_len );
517
+ FILTERX_STRING_DECLARE_ON_STACK (text_obj , new_text ? new_text -> str : text , new_text ? new_text -> len : text_len );
523
518
524
519
if (!filterx_object_set_subscript (elem_context -> current_obj , key , & text_obj ))
525
520
{
526
- const gchar * new_text = filterx_string_get_value_ref (text_obj , NULL );
527
- _set_error (error , "failed to add text to dict: \"#text\"=\"%s\"" , new_text );
521
+ _set_error (error , "failed to add text to dict: \"#text\"=\"%s\"" , new_text ? new_text -> str : text );
528
522
goto fail ;
529
523
}
530
524
0 commit comments