tuning trial: newobj with current ec
[ruby.git] / internal / array.h
blob44c0efbbc181415c46c1925ce0ad75e988eb5845
1 #ifndef INTERNAL_ARRAY_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_ARRAY_H
3 /**
4 * @file
5 * @author Ruby developers <ruby-core@ruby-lang.org>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @brief Internal header for Array.
12 #include "ruby/internal/config.h"
13 #include <stddef.h> /* for size_t */
14 #include "internal/static_assert.h" /* for STATIC_ASSERT */
15 #include "ruby/internal/stdbool.h" /* for bool */
16 #include "ruby/ruby.h" /* for RARRAY_LEN */
18 #ifndef ARRAY_DEBUG
19 # define ARRAY_DEBUG (0+RUBY_DEBUG)
20 #endif
22 #define RARRAY_PTR_IN_USE_FLAG FL_USER14
24 /* array.c */
25 VALUE rb_ary_last(int, const VALUE *, VALUE);
26 void rb_ary_set_len(VALUE, long);
27 void rb_ary_delete_same(VALUE, VALUE);
28 VALUE rb_ary_tmp_new_fill(long capa);
29 VALUE rb_ary_at(VALUE, VALUE);
30 size_t rb_ary_memsize(VALUE);
31 VALUE rb_to_array_type(VALUE obj);
32 void rb_ary_cancel_sharing(VALUE ary);
34 static inline VALUE rb_ary_entry_internal(VALUE ary, long offset);
35 static inline bool ARY_PTR_USING_P(VALUE ary);
36 static inline void RARY_TRANSIENT_SET(VALUE ary);
37 static inline void RARY_TRANSIENT_UNSET(VALUE ary);
39 RUBY_SYMBOL_EXPORT_BEGIN
40 /* array.c (export) */
41 void rb_ary_detransient(VALUE a);
42 VALUE *rb_ary_ptr_use_start(VALUE ary);
43 void rb_ary_ptr_use_end(VALUE ary);
44 RUBY_SYMBOL_EXPORT_END
46 MJIT_SYMBOL_EXPORT_BEGIN
47 VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
48 VALUE rb_check_to_array(VALUE ary);
49 VALUE rb_ary_behead(VALUE, long);
50 VALUE rb_ary_aref1(VALUE ary, VALUE i);
52 struct rb_execution_context_struct;
53 VALUE rb_ec_ary_new_from_values(struct rb_execution_context_struct *ec, long n, const VALUE *elts);
54 MJIT_SYMBOL_EXPORT_END
56 static inline VALUE
57 rb_ary_entry_internal(VALUE ary, long offset)
59 long len = RARRAY_LEN(ary);
60 const VALUE *ptr = RARRAY_CONST_PTR_TRANSIENT(ary);
61 if (len == 0) return Qnil;
62 if (offset < 0) {
63 offset += len;
64 if (offset < 0) return Qnil;
66 else if (len <= offset) {
67 return Qnil;
69 return ptr[offset];
72 static inline bool
73 ARY_PTR_USING_P(VALUE ary)
75 return FL_TEST_RAW(ary, RARRAY_PTR_IN_USE_FLAG);
78 static inline void
79 RARY_TRANSIENT_SET(VALUE ary)
81 #if USE_TRANSIENT_HEAP
82 FL_SET_RAW(ary, RARRAY_TRANSIENT_FLAG);
83 #endif
86 static inline void
87 RARY_TRANSIENT_UNSET(VALUE ary)
89 #if USE_TRANSIENT_HEAP
90 FL_UNSET_RAW(ary, RARRAY_TRANSIENT_FLAG);
91 #endif
94 #undef rb_ary_new_from_args
95 #if RBIMPL_HAS_WARNING("-Wgnu-zero-variadic-macro-arguments")
96 # /* Skip it; clang -pedantic doesn't like the following */
97 #elif defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
98 #define rb_ary_new_from_args(n, ...) \
99 __extension__ ({ \
100 const VALUE args_to_new_ary[] = {__VA_ARGS__}; \
101 if (__builtin_constant_p(n)) { \
102 STATIC_ASSERT(rb_ary_new_from_args, numberof(args_to_new_ary) == (n)); \
104 rb_ary_new_from_values(numberof(args_to_new_ary), args_to_new_ary); \
106 #endif
108 #undef RARRAY_AREF
109 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
110 RBIMPL_ATTR_ARTIFICIAL()
111 static inline VALUE
112 RARRAY_AREF(VALUE ary, long i)
114 RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
116 return RARRAY_CONST_PTR_TRANSIENT(ary)[i];
119 #endif /* INTERNAL_ARRAY_H */