Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
compar.h
1#ifndef INTERNAL_COMPAR_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_COMPAR_H
11#include "internal/basic_operators.h"
12
13#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
14
15#define CMP_OPTIMIZABLE(type) BASIC_OP_UNREDEFINED_P(BOP_CMP, type##_REDEFINED_OP_FLAG)
16
17#define OPTIMIZED_CMP(a, b) \
18 ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(INTEGER)) ? \
19 (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
20 (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(STRING)) ? \
21 rb_str_cmp(a, b) : \
22 (RB_FLOAT_TYPE_P(a) && RB_FLOAT_TYPE_P(b) && CMP_OPTIMIZABLE(FLOAT)) ? \
23 rb_float_cmp(a, b) : \
24 rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
25
26/* compar.c */
27VALUE rb_invcmp(VALUE, VALUE);
28
29#endif /* INTERNAL_COMPAR_H */
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40