Ruby: internal/compar.h Source File

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

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 */
27 VALUE rb_invcmp(VALUE, VALUE);
28
29#endif /* INTERNAL_COMPAR_H */
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40