@@ -288,27 +288,27 @@ static void connector_encode_lc(const char *lc_string, condesc_t *desc)
288
288
*
289
289
* Note: check_connector() has already validated the connector string.
290
290
*/
291
- void calculate_connector_info (hdesc_t * hdesc )
291
+ void calculate_connector_info (condesc_t * condesc )
292
292
{
293
293
const char * s ;
294
+ condesc_more_t * m = condesc -> more ;
294
295
295
- s = hdesc -> string ;
296
+ s = m -> string ;
296
297
if (islower ((unsigned char )* s ))
297
298
{
298
- dassert ((hdesc -> string [0 ] == 'h' ) || (hdesc -> string [0 ] == 'd' ),
299
- "\'%hdesc\': Bad head/dependent character" , hdesc -> string [0 ]);
299
+ dassert ((s [0 ] == 'h' ) || (s [0 ] == 'd' ), "'%s': Bad head/dependent" , s );
300
300
301
- if ((* s == 'h' ) || (* s == 'd' )) hdesc -> flags |= CD_HEAD_DEPENDENT ;
302
- if (* s == 'h' ) hdesc -> flags |= CD_HEAD ;
301
+ if ((s [ 0 ] == 'h' ) || (s [ 0 ] == 'd' )) m -> flags |= CD_HEAD_DEPENDENT ;
302
+ if (s [ 0 ] == 'h' ) m -> flags |= CD_HEAD ;
303
303
s ++ ; /* Ignore head-dependent indicator. */
304
304
}
305
305
306
- hdesc -> uc_start = (uint8_t )(s - hdesc -> string );
306
+ m -> uc_start = (uint8_t )(s - m -> string );
307
307
/* Skip the uppercase part. */
308
308
do { s ++ ; } while (is_connector_name_char (* s ));
309
- hdesc -> uc_length = (uint8_t )(s - hdesc -> string - hdesc -> uc_start );
309
+ m -> uc_length = (uint8_t )(s - m -> string - m -> uc_start );
310
310
311
- connector_encode_lc (s , hdesc -> desc );
311
+ connector_encode_lc (s , condesc );
312
312
}
313
313
314
314
/* ================= Connector descriptor table. ====================== */
@@ -407,35 +407,36 @@ int condesc_by_uc_constring(const void * a, const void * b)
407
407
*/
408
408
static bool sort_condesc_by_uc_constring (Dictionary dict )
409
409
{
410
- if ((0 == dict -> contable .num_con ) && !IS_DYNAMIC_DICT (dict ))
410
+ ConTable * ct = & dict -> contable ;
411
+
412
+ if ((0 == ct -> num_con ) && !IS_DYNAMIC_DICT (dict ))
411
413
{
412
414
prt_error ("Error: Dictionary %s: No connectors found.\n" , dict -> name );
413
415
return false;
414
416
}
415
417
416
418
/* An SQL dict without <UNKNOWN-WORD> may have 0 connectors here. */
417
- if (0 == dict -> contable . num_con )
419
+ if (0 == ct -> num_con )
418
420
return true;
419
421
420
- condesc_t * * sdesc = malloc (dict -> contable . num_con * sizeof (condesc_t * ));
422
+ condesc_t * * sdesc = malloc (ct -> num_con * sizeof (condesc_t * ));
421
423
size_t i = 0 ;
422
- for (size_t n = 0 ; n < dict -> contable . size ; n ++ )
424
+ for (size_t n = 0 ; n < ct -> size ; n ++ )
423
425
{
424
- condesc_t * condesc = dict -> contable . hdesc [n ].desc ;
426
+ condesc_t * condesc = ct -> hdesc [n ].desc ;
425
427
426
428
if (NULL == condesc ) continue ;
427
- calculate_connector_info (& dict -> contable . hdesc [ n ] );
428
- sdesc [i ++ ] = dict -> contable . hdesc [ n ]. desc ;
429
+ calculate_connector_info (condesc );
430
+ sdesc [i ++ ] = condesc ;
429
431
}
430
432
431
- qsort (sdesc , dict -> contable .num_con , sizeof (* dict -> contable .sdesc ),
432
- condesc_by_uc_constring );
433
+ qsort (sdesc , ct -> num_con , sizeof (* ct -> sdesc ), condesc_by_uc_constring );
433
434
434
435
/* Enumerate the connectors according to their UC part. */
435
436
int uc_num = 0 ;
436
437
437
438
sdesc [0 ]-> uc_num = uc_num ;
438
- for (size_t n = 1 ; n < dict -> contable . num_con ; n ++ )
439
+ for (size_t n = 1 ; n < ct -> num_con ; n ++ )
439
440
{
440
441
condesc_t * * condesc = & sdesc [n ];
441
442
@@ -461,10 +462,10 @@ static bool sort_condesc_by_uc_constring(Dictionary dict)
461
462
462
463
lgdebug (+11 , "Dictionary %s: %zu different connectors "
463
464
"(%d with a different UC part)\n" ,
464
- dict -> name , dict -> contable . num_con , uc_num + 1 );
465
+ dict -> name , ct -> num_con , uc_num + 1 );
465
466
466
- dict -> contable . sdesc = sdesc ;
467
- dict -> contable . num_uc = uc_num + 1 ;
467
+ ct -> sdesc = sdesc ;
468
+ ct -> num_uc = uc_num + 1 ;
468
469
469
470
/* hdesc is not freed here because it is needed for finding ZZZ.
470
471
* It could be freed here if we have ZZZ cached in the dict structure. */
@@ -477,6 +478,7 @@ void condesc_delete(Dictionary dict)
477
478
478
479
free (ct -> hdesc );
479
480
pool_delete (ct -> desc_pool );
481
+ pool_delete (ct -> more_pool );
480
482
condesc_length_limit_def_delete (ct );
481
483
}
482
484
@@ -488,14 +490,15 @@ void condesc_reuse(Dictionary dict)
488
490
ct -> num_uc = 0 ;
489
491
memset (ct -> hdesc , 0 , ct -> size * sizeof (hdesc_t ));
490
492
pool_reuse (ct -> desc_pool );
493
+ pool_reuse (ct -> more_pool );
491
494
}
492
495
493
496
static hdesc_t * condesc_find (ConTable * ct , const char * constring , uint32_t hash )
494
497
{
495
498
uint32_t i = hash & (ct -> size - 1 );
496
499
497
500
while ((NULL != ct -> hdesc [i ].desc ) &&
498
- !string_set_cmp (constring , ct -> hdesc [i ].string ))
501
+ !string_set_cmp (constring , ct -> hdesc [i ].desc -> more -> string ))
499
502
{
500
503
i = (i + 1 ) & (ct -> size - 1 );
501
504
}
@@ -522,18 +525,18 @@ static bool condesc_grow(ConTable *ct)
522
525
523
526
for (size_t i = 0 ; i < old_size ; i ++ )
524
527
{
525
- hdesc_t * old_h = & old_hdesc [i ];
526
- if (NULL == old_h -> desc ) continue ;
527
- hdesc_t * new_h = condesc_find (ct , old_h -> string , old_h -> str_hash );
528
+ condesc_t * old_desc = old_hdesc [i ].desc ;
529
+ if (NULL == old_desc ) continue ;
530
+ hdesc_t * new_hdesc =
531
+ condesc_find (ct , old_desc -> more -> string , old_desc -> more -> str_hash );
528
532
529
- if (NULL != new_h -> desc )
533
+ if (NULL != new_hdesc -> desc )
530
534
{
531
535
prt_error ("Fatal Error: condesc_grow(): Internal error\n" );
532
536
free (old_hdesc );
533
537
return false;
534
538
}
535
- * new_h = * old_h ;
536
- new_h -> desc -> more = new_h ;
539
+ new_hdesc -> desc = old_desc ;
537
540
}
538
541
539
542
free (old_hdesc );
@@ -548,12 +551,15 @@ condesc_t *condesc_add(ConTable *ct, const char *constring)
548
551
if (NULL == h -> desc )
549
552
{
550
553
lgdebug (+11 , "Creating connector '%s' (%zu)\n" , constring , ct -> num_con );
554
+
551
555
h -> desc = pool_alloc (ct -> desc_pool );
552
- h -> string = constring ;
553
556
h -> desc -> uc_num = UINT32_MAX ;
554
- h -> str_hash = hash ;
555
- h -> desc -> more = h ;
556
557
h -> desc -> con_num = ct -> num_con ;
558
+
559
+ condesc_more_t * m = h -> desc -> more = pool_alloc (ct -> desc_pool );
560
+ m -> string = constring ;
561
+ m -> str_hash = hash ;
562
+
557
563
ct -> num_con ++ ;
558
564
559
565
if ((8 * ct -> num_con ) > (3 * ct -> size ))
@@ -573,6 +579,9 @@ void condesc_init(Dictionary dict, size_t num_con)
573
579
ct -> desc_pool = pool_new (__func__ , "condesc_t" ,
574
580
/*num_elements*/ num_con , sizeof (condesc_t ),
575
581
/*zero_out*/ true, /*align*/ true, /*exact*/ false);
582
+ ct -> more_pool = pool_new (__func__ , "condesc_more_t" ,
583
+ /*num_elements*/ num_con , sizeof (condesc_more_t ),
584
+ /*zero_out*/ true, /*align*/ true, /*exact*/ false);
576
585
577
586
// Connector hash table must be an exact power of two.
578
587
int nbits = 0 ;
0 commit comments