Changeset 439 for EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h
- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h
r331 r439 1 /* 2 ** mruby/array.h - Array class1 /** 2 ** @file mruby/array.h - Array class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 18 18 typedef struct mrb_shared_array { 19 19 int refcnt; 20 mrb_ intlen;20 mrb_ssize len; 21 21 mrb_value *ptr; 22 22 } mrb_shared_array; 23 23 24 #define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value))) 24 25 struct RArray { 25 26 MRB_OBJECT_HEADER; 26 mrb_int len;27 27 union { 28 mrb_int capa; 29 mrb_shared_array *shared; 30 } aux; 31 mrb_value *ptr; 28 struct { 29 mrb_ssize len; 30 union { 31 mrb_ssize capa; 32 mrb_shared_array *shared; 33 } aux; 34 mrb_value *ptr; 35 } heap; 36 void *ary[3]; 37 } as; 32 38 }; 33 39 … … 36 42 #define RARRAY(v) ((struct RArray*)(mrb_ptr(v))) 37 43 38 #define RARRAY_LEN(a) (RARRAY(a)->len) 39 #define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr) 44 #define MRB_ARY_EMBED_MASK 7 45 #define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK) 46 #define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK)) 47 #define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1)) 48 #define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1)) 49 #define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary)) 50 51 #define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len) 52 #define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr) 53 #define RARRAY_LEN(a) ARY_LEN(RARRAY(a)) 54 #define RARRAY_PTR(a) ARY_PTR(RARRAY(a)) 55 #define ARY_SET_LEN(a,n) do {\ 56 if (ARY_EMBED_P(a)) {\ 57 mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \ 58 ARY_SET_EMBED_LEN(a,n);\ 59 }\ 60 else\ 61 (a)->as.heap.len = (n);\ 62 } while (0) 63 #define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa) 40 64 #define MRB_ARY_SHARED 256 41 65 #define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED) … … 176 200 */ 177 201 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other); 202 MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self); 178 203 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self); 179 204 180 205 /* 181 * Unshift an element into anarray206 * Unshift an element into the array 182 207 * 183 208 * Equivalent to: … … 190 215 */ 191 216 MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item); 217 218 /* 219 * Get nth element in the array 220 * 221 * Equivalent to: 222 * 223 * ary[offset] 224 * 225 * @param ary The target array. 226 * @param offset The element position (negative counts from the tail). 227 */ 192 228 MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset); 229 230 /* 231 * Replace subsequence of an array. 232 * 233 * Equivalent to: 234 * 235 * ary.shift 236 * 237 * @param mrb The mruby state reference. 238 * @param self The array from which the value will be shifted. 239 * @param head Beginning position of a replacement subsequence. 240 * @param len Length of a replacement subsequence. 241 * @param rpl The array of replacement elements. 242 * @return The receiver array. 243 */ 244 MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl); 193 245 194 246 /* … … 206 258 207 259 /* 208 * Removes all elements from th isarray260 * Removes all elements from the array 209 261 * 210 262 * Equivalent to: … … 240 292 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len); 241 293 242 static inline mrb_int243 mrb_ary_len(mrb_state *mrb, mrb_value ary)244 {245 (void)mrb;246 mrb_assert(mrb_array_p(ary));247 return RARRAY_LEN(ary);248 }249 250 static inline mrb_value251 ary_elt(mrb_value ary, mrb_int offset)252 {253 if (offset < 0 || RARRAY_LEN(ary) <= offset) {254 return mrb_nil_value();255 }256 return RARRAY_PTR(ary)[offset];257 }258 259 294 MRB_END_DECL 260 295
Note:
See TracChangeset
for help on using the changeset viewer.