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
2e0c1b43
Unverified
Commit
2e0c1b43
authored
Nov 09, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
etc.c: improve `mrb_obj_id` with NaN boxing and Word boxing.
parent
a5567fba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
src/etc.c
src/etc.c
+30
-11
No files found.
src/etc.c
View file @
2e0c1b43
...
...
@@ -103,29 +103,47 @@ mrb_float_id(mrb_float f)
MRB_API
mrb_int
mrb_obj_id
(
mrb_value
obj
)
{
mrb_int
tt
=
mrb_type
(
obj
);
#if defined(MRB_NAN_BOXING)
#ifdef MRB_INT64
return
obj
.
u
;
#else
uint64_t
u
=
obj
.
u
;
return
(
mrb_int
)(
u
>>
32
)
^
u
;
#endif
#elif defined(MRB_WORD_BOXING)
if
(
!
mrb_immediate_p
(
obj
))
{
if
(
mrb_integer_p
(
obj
))
return
mrb_integer
(
obj
);
#ifndef MRB_NO_FLOAT
if
(
mrb_float_p
(
obj
))
{
return
mrb_float_id
(
mrb_float
(
obj
));
}
#endif
}
return
(
mrb_int
)
obj
.
w
;
#else
/* MRB_NO_BOXING */
#define MakeID2(p,t) (mrb_int)(((intptr_t)(p))^(t))
#define MakeID(p) MakeID2(p,tt)
#define MakeID(p,t) (mrb_int)(((intptr_t)(p))^(t))
enum
mrb_vtype
tt
=
mrb_type
(
obj
);
switch
(
tt
)
{
case
MRB_TT_FREE
:
case
MRB_TT_UNDEF
:
return
MakeID
(
0
);
/* not define
*/
return
MakeID
(
0
,
tt
);
/* should not happen
*/
case
MRB_TT_FALSE
:
if
(
mrb_nil_p
(
obj
))
return
MakeID
(
4
);
return
MakeID
(
4
,
tt
);
else
return
MakeID
(
0
);
return
MakeID
(
0
,
tt
);
case
MRB_TT_TRUE
:
return
MakeID
(
2
);
return
MakeID
(
2
,
tt
);
case
MRB_TT_SYMBOL
:
return
MakeID
(
mrb_symbol
(
obj
));
return
MakeID
(
mrb_symbol
(
obj
)
,
tt
);
case
MRB_TT_INTEGER
:
return
MakeID
(
mrb_int_id
(
mrb_integer
(
obj
)));
return
MakeID
(
mrb_int_id
(
mrb_integer
(
obj
))
,
tt
);
#ifndef MRB_NO_FLOAT
case
MRB_TT_FLOAT
:
return
MakeID
(
mrb_float_id
(
mrb_float
(
obj
)));
return
MakeID
(
mrb_float_id
(
mrb_float
(
obj
))
,
tt
);
#endif
case
MRB_TT_STRING
:
case
MRB_TT_OBJECT
:
...
...
@@ -141,8 +159,9 @@ mrb_obj_id(mrb_value obj)
case
MRB_TT_DATA
:
case
MRB_TT_ISTRUCT
:
default:
return
MakeID
(
mrb_ptr
(
obj
));
return
MakeID
(
mrb_ptr
(
obj
)
,
tt
);
}
#endif
}
#ifdef MRB_WORD_BOXING
...
...
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