@@ -354,9 +354,6 @@ static struct ins_ops nop_ops = {
354
354
.scnprintf = nop__scnprintf ,
355
355
};
356
356
357
- /*
358
- * Must be sorted by name!
359
- */
360
357
static struct ins instructions [] = {
361
358
{ .name = "add" , .ops = & mov_ops , },
362
359
{ .name = "addl" , .ops = & mov_ops , },
@@ -449,18 +446,39 @@ static struct ins instructions[] = {
449
446
{ .name = "xbeginq" , .ops = & jump_ops , },
450
447
};
451
448
452
- static int ins__cmp (const void * name , const void * insp )
449
+ static int ins__key_cmp (const void * name , const void * insp )
453
450
{
454
451
const struct ins * ins = insp ;
455
452
456
453
return strcmp (name , ins -> name );
457
454
}
458
455
456
+ static int ins__cmp (const void * a , const void * b )
457
+ {
458
+ const struct ins * ia = a ;
459
+ const struct ins * ib = b ;
460
+
461
+ return strcmp (ia -> name , ib -> name );
462
+ }
463
+
464
+ static void ins__sort (void )
465
+ {
466
+ const int nmemb = ARRAY_SIZE (instructions );
467
+
468
+ qsort (instructions , nmemb , sizeof (struct ins ), ins__cmp );
469
+ }
470
+
459
471
static struct ins * ins__find (const char * name )
460
472
{
461
473
const int nmemb = ARRAY_SIZE (instructions );
474
+ static bool sorted ;
475
+
476
+ if (!sorted ) {
477
+ ins__sort ();
478
+ sorted = true;
479
+ }
462
480
463
- return bsearch (name , instructions , nmemb , sizeof (struct ins ), ins__cmp );
481
+ return bsearch (name , instructions , nmemb , sizeof (struct ins ), ins__key_cmp );
464
482
}
465
483
466
484
int symbol__annotate_init (struct map * map __maybe_unused , struct symbol * sym )
0 commit comments