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
bd426821
Unverified
Commit
bd426821
authored
Dec 10, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class.c: implement method cache (off by default).
parent
523197c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
src/class.c
src/class.c
+17
-0
No files found.
src/class.c
View file @
bd426821
...
...
@@ -37,6 +37,11 @@ typedef struct mt_tbl {
struct
mt_elem
*
table
;
}
mt_tbl
;
#ifdef MRB_USE_INLINE_METHOD_CACHE
#define MT_CACHE_SIZE 256
static
uint8_t
mt_cache
[
MT_CACHE_SIZE
];
#endif
/* Creates the method table. */
static
mt_tbl
*
mt_new
(
mrb_state
*
mrb
)
...
...
@@ -142,11 +147,23 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym)
if
(
t
->
size
==
0
)
return
NULL
;
hash
=
kh_int_hash_func
(
mrb
,
sym
);
#ifdef MRB_USE_INLINE_METHOD_CACHE
size_t
cpos
=
(
hash
^
(
uintptr_t
)
t
)
%
MT_CACHE_SIZE
;
pos
=
mt_cache
[
cpos
];
if
(
cpos
<
t
->
alloc
&&
t
->
table
[
cpos
].
key
==
sym
)
{
return
&
t
->
table
[
cpos
];
}
#endif
start
=
pos
=
hash
&
(
t
->
alloc
-
1
);
for
(;;)
{
struct
mt_elem
*
slot
=
&
t
->
table
[
pos
];
if
(
slot
->
key
==
sym
)
{
#ifdef MRB_USE_INLINE_METHOD_CACHE
if
(
pos
<
0xff
)
{
mt_cache
[
cpos
]
=
pos
;
}
#endif
return
slot
;
}
else
if
(
slot_empty_p
(
slot
))
{
...
...
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