Project

General

Profile

Feature #15721 ยป optimize-comparable-condition.patch

masarakki (masaki yamada), 03/22/2019 06:24 AM

View differences:

vm_insnhelper.c
1469 1469
#endif
1470 1470
}
1471 1471

  
1472
static inline int
1473
special_const_comparability(VALUE obj)
1474
{
1475
    switch (TYPE(obj)) {
1476
      case T_FIXNUM:
1477
	return (EQ_UNREDEFINED_P(INTEGER) != 0) * 2 - 1;
1478
      case T_FLOAT:
1479
        return (EQ_UNREDEFINED_P(FLOAT) != 0) * 2 - 1;
1480
      case T_SYMBOL:
1481
        return (EQ_UNREDEFINED_P(SYMBOL) != 0) * 2 - 1;
1482
      case T_NIL:
1483
        return (EQ_UNREDEFINED_P(NIL) != 0) * 2 - 1;
1484
      case T_TRUE:
1485
        return (EQ_UNREDEFINED_P(TRUE) != 0) * 2 - 1;
1486
      case T_FALSE:
1487
        return (EQ_UNREDEFINED_P(FALSE) != 0) * 2 - 1;
1488
      default:
1489
        UNREACHABLE_RETURN(0);
1490
    }
1491
}
1492

  
1472 1493
/* 1: compare by identity, 0: not applicable, -1: redefined */
1473 1494
static inline int
1474 1495
comparable_by_identity(VALUE recv, VALUE obj)
......
1482 1503
    if (SYMBOL_P(recv) && SYMBOL_P(obj)) {
1483 1504
	return (EQ_UNREDEFINED_P(SYMBOL) != 0) * 2 - 1;
1484 1505
    }
1506
    if ((FIXNUM_P(recv) && FLONUM_P(obj)) ||
1507
        (FLONUM_P(recv) && FIXNUM_P(obj))) {
1508
        return 0; // numerical conversion costs
1509
    }
1510
    if (SPECIAL_CONST_P(recv) && SPECIAL_CONST_P(obj)) {
1511
        int recv_comparability = special_const_comparability(recv);
1512
        int obj_comparability = special_const_comparability(obj);
1513
        return MIN(recv_comparability, obj_comparability);
1514
    }
1485 1515
    return 0;
1486 1516
}
1487 1517