Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
75ec86ed
Commit
75ec86ed
authored
Aug 18, 2017
by
Miura Hideki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Array structure
parent
8bf492f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
include/mruby/array.h
include/mruby/array.h
+6
-7
src/array.c
src/array.c
+1
-3
No files found.
include/mruby/array.h
View file @
75ec86ed
...
@@ -41,13 +41,12 @@ struct RArray {
...
@@ -41,13 +41,12 @@ struct RArray {
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#define MRB_ARY_EMBED 4
#define MRB_ARY_EMBED_MASK 7
#define MRB_ARY_EMBED_MASK 3
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED)
//#define ARY_SET_EMBED_FLAG(a) ((a)->flags |= MRB_ARY_EMBED)
#define ARY_SET_EMBED_FLAG(a) ((a)->flags |= MRB_ARY_EMBED)
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED|MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) (((a)->flags & MRB_ARY_EMBED_MASK) - 1)
#define ARY_EMBED_LEN(a) ((mrb_int)((a)->flags & MRB_ARY_EMBED_MASK))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | (len + 1))
#define ARY_SET_EMBED_LEN(a,len) (a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((len)&MRB_ARY_EMBED_MASK);
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
...
...
src/array.c
View file @
75ec86ed
...
@@ -29,8 +29,7 @@ ary_new_capa(mrb_state *mrb, mrb_int capa)
...
@@ -29,8 +29,7 @@ ary_new_capa(mrb_state *mrb, mrb_int capa)
a
=
(
struct
RArray
*
)
mrb_obj_alloc
(
mrb
,
MRB_TT_ARRAY
,
mrb
->
array_class
);
a
=
(
struct
RArray
*
)
mrb_obj_alloc
(
mrb
,
MRB_TT_ARRAY
,
mrb
->
array_class
);
if
(
capa
<=
MRB_ARY_EMBED_LEN_MAX
)
{
if
(
capa
<=
MRB_ARY_EMBED_LEN_MAX
)
{
ARY_SET_EMBED_FLAG
(
a
);
ARY_SET_EMBED_LEN
(
a
,
0
);
/* ARY_SET_EMBED_LEN(a, 0); */
}
}
else
{
else
{
a
->
as
.
heap
.
ptr
=
(
mrb_value
*
)
mrb_malloc
(
mrb
,
blen
);
a
->
as
.
heap
.
ptr
=
(
mrb_value
*
)
mrb_malloc
(
mrb
,
blen
);
...
@@ -1048,7 +1047,6 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self)
...
@@ -1048,7 +1047,6 @@ mrb_ary_clear(mrb_state *mrb, mrb_value self)
else
if
(
!
ARY_EMBED_P
(
a
)){
else
if
(
!
ARY_EMBED_P
(
a
)){
mrb_free
(
mrb
,
a
->
as
.
heap
.
ptr
);
mrb_free
(
mrb
,
a
->
as
.
heap
.
ptr
);
}
}
ARY_SET_EMBED_FLAG
(
a
);
ARY_SET_EMBED_LEN
(
a
,
0
);
ARY_SET_EMBED_LEN
(
a
,
0
);
return
self
;
return
self
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment