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
ccd871bc
Commit
ccd871bc
authored
Jun 06, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce calling mrb_sym2name_len() from struct.c; ref #2365
parent
b533917a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
11 deletions
+12
-11
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+12
-11
No files found.
mrbgems/mruby-struct/src/struct.c
View file @
ccd871bc
...
...
@@ -211,16 +211,16 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj)
}
static
mrb_bool
mrb_is_local_id
(
mrb_state
*
mrb
,
mrb_sym
id
)
is_local_id
(
mrb_state
*
mrb
,
const
char
*
name
)
{
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
NULL
)
;
if
(
!
name
)
return
FALSE
;
return
!
ISUPPER
(
name
[
0
]);
}
static
mrb_bool
mrb_is_const_id
(
mrb_state
*
mrb
,
mrb_sym
id
)
is_const_id
(
mrb_state
*
mrb
,
const
char
*
name
)
{
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
NULL
)
;
if
(
!
name
)
return
FALSE
;
return
ISUPPER
(
name
[
0
]);
}
...
...
@@ -240,7 +240,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
/* old style: should we warn? */
name
=
mrb_str_to_str
(
mrb
,
name
);
id
=
mrb_obj_to_sym
(
mrb
,
name
);
if
(
!
mrb_is_const_id
(
mrb
,
id
))
{
if
(
!
is_const_id
(
mrb
,
mrb_sym2name_len
(
mrb
,
id
,
NULL
)
))
{
mrb_name_error
(
mrb
,
id
,
"identifier %S needs to be constant"
,
name
);
}
if
(
mrb_const_defined_at
(
mrb
,
klass
,
id
))
{
...
...
@@ -262,7 +262,9 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
ai
=
mrb_gc_arena_save
(
mrb
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
mrb_sym
id
=
mrb_symbol
(
ptr_members
[
i
]);
if
(
mrb_is_local_id
(
mrb
,
id
)
||
mrb_is_const_id
(
mrb
,
id
))
{
const
char
*
name
=
mrb_sym2name_len
(
mrb
,
id
,
NULL
);
if
(
is_local_id
(
mrb
,
name
)
||
is_const_id
(
mrb
,
name
))
{
if
(
i
<
N_REF_FUNC
)
{
mrb_define_method_id
(
mrb
,
c
,
id
,
ref_func
[
i
],
MRB_ARGS_NONE
());
}
...
...
@@ -429,6 +431,8 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur)
for
(
i
=
0
;
i
<
len
;
i
++
)
{
mrb_value
slot
;
mrb_sym
id
;
const
char
*
name
;
mrb_int
len
;
if
(
i
>
0
)
{
mrb_str_cat_lit
(
mrb
,
str
,
", "
);
...
...
@@ -438,11 +442,8 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur)
}
slot
=
ptr_members
[
i
];
id
=
mrb_symbol
(
slot
);
if
(
mrb_is_local_id
(
mrb
,
id
)
||
mrb_is_const_id
(
mrb
,
id
))
{
const
char
*
name
;
mrb_int
len
;
name
=
mrb_sym2name_len
(
mrb
,
id
,
&
len
);
name
=
mrb_sym2name_len
(
mrb
,
id
,
&
len
);
if
(
is_local_id
(
mrb
,
name
)
||
is_const_id
(
mrb
,
name
))
{
mrb_str_append
(
mrb
,
str
,
mrb_str_new
(
mrb
,
name
,
len
));
}
else
{
...
...
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