Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
compar.h
Go to the documentation of this file.
1#ifndef INTERNAL_COMPAR_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_COMPAR_H
12#include "internal/vm.h" /* for rb_method_basic_definition_p */
13
14#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
15
16enum {
21};
22
24 unsigned int opt_methods;
25 unsigned int opt_inited;
26};
27
28#define NEW_CMP_OPT_MEMO(type, value) \
29 NEW_PARTIAL_MEMO_FOR(type, value, cmp_opt)
30#define CMP_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(cmp_opt_,type))
31#define CMP_OPTIMIZABLE(data, type) \
32 (((data).opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
33 ((data).opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
34 (((data).opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
35 rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
36 ((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
37
38#define OPTIMIZED_CMP(a, b, data) \
39 ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Integer)) ? \
40 (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
41 (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) ? \
42 rb_str_cmp(a, b) : \
43 (RB_FLOAT_TYPE_P(a) && RB_FLOAT_TYPE_P(b) && CMP_OPTIMIZABLE(data, Float)) ? \
44 rb_float_cmp(a, b) : \
45 rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
46
47/* compar.c */
49
50#endif /* INTERNAL_COMPAR_H */
@ cmp_opt_Float
Definition: compar.h:19
@ cmp_optimizable_count
Definition: compar.h:20
@ cmp_opt_String
Definition: compar.h:18
@ cmp_opt_Integer
Definition: compar.h:17
VALUE rb_invcmp(VALUE, VALUE)
Definition: compar.c:50
Internal header for RubyVM.
unsigned int opt_inited
Definition: compar.h:25
unsigned int opt_methods
Definition: compar.h:24
unsigned long VALUE
Definition: value.h:38