Index: EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h
===================================================================
--- EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/array.h	(revision 331)
+++ EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/array.h	(revision 439)
@@ -1,4 +1,4 @@
-/*
-** mruby/array.h - Array class
+/**
+** @file mruby/array.h - Array class
 **
 ** See Copyright Notice in mruby.h
@@ -18,16 +18,22 @@
 typedef struct mrb_shared_array {
   int refcnt;
-  mrb_int len;
+  mrb_ssize len;
   mrb_value *ptr;
 } mrb_shared_array;
 
+#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
 struct RArray {
   MRB_OBJECT_HEADER;
-  mrb_int len;
   union {
-    mrb_int capa;
-    mrb_shared_array *shared;
-  } aux;
-  mrb_value *ptr;
+    struct {
+      mrb_ssize len;
+      union {
+        mrb_ssize capa;
+        mrb_shared_array *shared;
+      } aux;
+      mrb_value *ptr;
+    } heap;
+    void *ary[3];
+  } as;
 };
 
@@ -36,6 +42,24 @@
 #define RARRAY(v)  ((struct RArray*)(mrb_ptr(v)))
 
-#define RARRAY_LEN(a) (RARRAY(a)->len)
-#define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
+#define MRB_ARY_EMBED_MASK  7
+#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
+#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
+#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
+#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
+#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary))
+
+#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
+#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
+#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
+#define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
+#define ARY_SET_LEN(a,n) do {\
+  if (ARY_EMBED_P(a)) {\
+    mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
+    ARY_SET_EMBED_LEN(a,n);\
+  }\
+  else\
+    (a)->as.heap.len = (n);\
+} while (0)
+#define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
 #define MRB_ARY_SHARED      256
 #define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
@@ -176,8 +200,9 @@
  */
 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
+MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self);
 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
 
 /*
- * Unshift an element into an array
+ * Unshift an element into the array
  *
  * Equivalent to:
@@ -190,5 +215,32 @@
  */
 MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
+
+/*
+ * Get nth element in the array
+ *
+ * Equivalent to:
+ *
+ *     ary[offset]
+ *
+ * @param ary The target array.
+ * @param offset The element position (negative counts from the tail).
+ */
 MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
+
+/*
+ * Replace subsequence of an array.
+ *
+ * Equivalent to:
+ *
+ *      ary.shift
+ *
+ * @param mrb The mruby state reference.
+ * @param self The array from which the value will be shifted.
+ * @param head Beginning position of a replacement subsequence.
+ * @param len Length of a replacement subsequence.
+ * @param rpl The array of replacement elements.
+ * @return The receiver array.
+ */
+MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
 
 /*
@@ -206,5 +258,5 @@
 
 /*
- * Removes all elements from this array
+ * Removes all elements from the array
  *
  * Equivalent to:
@@ -240,21 +292,4 @@
 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
 
-static inline mrb_int
-mrb_ary_len(mrb_state *mrb, mrb_value ary)
-{
-  (void)mrb;
-  mrb_assert(mrb_array_p(ary));
-  return RARRAY_LEN(ary);
-}
-
-static inline mrb_value
-ary_elt(mrb_value ary, mrb_int offset)
-{
-  if (offset < 0 || RARRAY_LEN(ary) <= offset) {
-    return mrb_nil_value();
-  }
-  return RARRAY_PTR(ary)[offset];
-}
-
 MRB_END_DECL
 
