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
eea418bc
Unverified
Commit
eea418bc
authored
Dec 30, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class.c, variable,c: replace `size_t` by `int`.
That reduce memory consumption by iv/mt tables.
parent
77f4a8b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
28 deletions
+26
-28
src/class.c
src/class.c
+13
-14
src/variable.c
src/variable.c
+13
-14
No files found.
src/class.c
View file @
eea418bc
...
@@ -36,8 +36,8 @@ union mt_ptr {
...
@@ -36,8 +36,8 @@ union mt_ptr {
/* method table structure */
/* method table structure */
typedef
struct
mt_tbl
{
typedef
struct
mt_tbl
{
size_
t
size
;
in
t
size
;
size_
t
alloc
;
in
t
alloc
;
union
mt_ptr
*
ptr
;
union
mt_ptr
*
ptr
;
}
mt_tbl
;
}
mt_tbl
;
...
@@ -65,8 +65,8 @@ static void mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, mrb_sym flags, union
...
@@ -65,8 +65,8 @@ static void mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, mrb_sym flags, union
static
void
static
void
mt_rehash
(
mrb_state
*
mrb
,
mt_tbl
*
t
)
mt_rehash
(
mrb_state
*
mrb
,
mt_tbl
*
t
)
{
{
size_
t
old_alloc
=
t
->
alloc
;
in
t
old_alloc
=
t
->
alloc
;
size_
t
new_alloc
=
old_alloc
+
8
;
in
t
new_alloc
=
old_alloc
+
8
;
union
mt_ptr
*
old_ptr
=
t
->
ptr
;
union
mt_ptr
*
old_ptr
=
t
->
ptr
;
khash_power2
(
new_alloc
);
khash_power2
(
new_alloc
);
...
@@ -79,7 +79,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
...
@@ -79,7 +79,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
old_ptr
[
old_alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
old_ptr
[
old_alloc
];
union
mt_ptr
*
vals
=
old_ptr
;
union
mt_ptr
*
vals
=
old_ptr
;
for
(
size_
t
i
=
0
;
i
<
old_alloc
;
i
++
)
{
for
(
in
t
i
=
0
;
i
<
old_alloc
;
i
++
)
{
mrb_sym
key
=
keys
[
i
];
mrb_sym
key
=
keys
[
i
];
if
(
MT_KEY_P
(
key
))
{
if
(
MT_KEY_P
(
key
))
{
mt_put
(
mrb
,
t
,
MT_KEY_SYM
(
key
),
MT_KEY_FLG
(
key
),
vals
[
i
]);
mt_put
(
mrb
,
t
,
MT_KEY_SYM
(
key
),
MT_KEY_FLG
(
key
),
vals
[
i
]);
...
@@ -94,8 +94,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
...
@@ -94,8 +94,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
static
void
static
void
mt_put
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
,
mrb_sym
flags
,
union
mt_ptr
ptr
)
mt_put
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
,
mrb_sym
flags
,
union
mt_ptr
ptr
)
{
{
size_t
hash
,
pos
,
start
;
int
hash
,
pos
,
start
,
dpos
=
-
1
;
ssize_t
dpos
=
-
1
;
if
(
t
->
alloc
==
0
)
{
if
(
t
->
alloc
==
0
)
{
mt_rehash
(
mrb
,
t
);
mt_rehash
(
mrb
,
t
);
...
@@ -140,7 +139,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, mrb_sym flags, union mt_ptr ptr)
...
@@ -140,7 +139,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, mrb_sym flags, union mt_ptr ptr)
static
mrb_sym
static
mrb_sym
mt_get
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
,
union
mt_ptr
*
pp
)
mt_get
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
,
union
mt_ptr
*
pp
)
{
{
size_
t
hash
,
pos
,
start
;
in
t
hash
,
pos
,
start
;
if
(
t
==
NULL
)
return
0
;
if
(
t
==
NULL
)
return
0
;
if
(
t
->
alloc
==
0
)
return
0
;
if
(
t
->
alloc
==
0
)
return
0
;
...
@@ -150,7 +149,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp)
...
@@ -150,7 +149,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp)
union
mt_ptr
*
vals
=
t
->
ptr
;
union
mt_ptr
*
vals
=
t
->
ptr
;
hash
=
kh_int_hash_func
(
mrb
,
sym
);
hash
=
kh_int_hash_func
(
mrb
,
sym
);
#ifdef MRB_USE_INLINE_METHOD_CACHE
#ifdef MRB_USE_INLINE_METHOD_CACHE
size_
t
cpos
=
(
hash
^
(
uintptr_t
)
t
)
%
MT_CACHE_SIZE
;
in
t
cpos
=
(
hash
^
(
uintptr_t
)
t
)
%
MT_CACHE_SIZE
;
pos
=
mt_cache
[
cpos
];
pos
=
mt_cache
[
cpos
];
if
(
cpos
<
t
->
alloc
&&
t
->
table
[
cpos
].
key
==
sym
)
{
if
(
cpos
<
t
->
alloc
&&
t
->
table
[
cpos
].
key
==
sym
)
{
return
&
t
->
table
[
cpos
];
return
&
t
->
table
[
cpos
];
...
@@ -182,7 +181,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp)
...
@@ -182,7 +181,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp)
static
mrb_bool
static
mrb_bool
mt_del
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
)
mt_del
(
mrb_state
*
mrb
,
mt_tbl
*
t
,
mrb_sym
sym
)
{
{
size_
t
hash
,
pos
,
start
;
in
t
hash
,
pos
,
start
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
...
@@ -213,7 +212,7 @@ static struct mt_tbl*
...
@@ -213,7 +212,7 @@ static struct mt_tbl*
mt_copy
(
mrb_state
*
mrb
,
mt_tbl
*
t
)
mt_copy
(
mrb_state
*
mrb
,
mt_tbl
*
t
)
{
{
mt_tbl
*
t2
;
mt_tbl
*
t2
;
size_
t
i
;
in
t
i
;
if
(
t
==
NULL
)
return
NULL
;
if
(
t
==
NULL
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
...
@@ -242,7 +241,7 @@ MRB_API void
...
@@ -242,7 +241,7 @@ MRB_API void
mrb_mt_foreach
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_mt_foreach_func
*
fn
,
void
*
p
)
mrb_mt_foreach
(
mrb_state
*
mrb
,
struct
RClass
*
c
,
mrb_mt_foreach_func
*
fn
,
void
*
p
)
{
{
mt_tbl
*
t
=
c
->
mt
;
mt_tbl
*
t
=
c
->
mt
;
size_
t
i
;
in
t
i
;
if
(
t
==
NULL
)
return
;
if
(
t
==
NULL
)
return
;
if
(
t
->
alloc
==
0
)
return
;
if
(
t
->
alloc
==
0
)
return
;
...
@@ -276,7 +275,7 @@ void
...
@@ -276,7 +275,7 @@ void
mrb_gc_mark_mt
(
mrb_state
*
mrb
,
struct
RClass
*
c
)
mrb_gc_mark_mt
(
mrb_state
*
mrb
,
struct
RClass
*
c
)
{
{
mt_tbl
*
t
=
c
->
mt
;
mt_tbl
*
t
=
c
->
mt
;
size_
t
i
;
in
t
i
;
if
(
t
==
NULL
)
return
;
if
(
t
==
NULL
)
return
;
if
(
t
->
alloc
==
0
)
return
;
if
(
t
->
alloc
==
0
)
return
;
...
@@ -299,7 +298,7 @@ mrb_gc_mark_mt_size(mrb_state *mrb, struct RClass *c)
...
@@ -299,7 +298,7 @@ mrb_gc_mark_mt_size(mrb_state *mrb, struct RClass *c)
struct
mt_tbl
*
h
=
c
->
mt
;
struct
mt_tbl
*
h
=
c
->
mt
;
if
(
!
h
)
return
0
;
if
(
!
h
)
return
0
;
return
h
->
size
;
return
(
size_t
)
h
->
size
;
}
}
void
void
...
...
src/variable.c
View file @
eea418bc
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
/* Instance variable table structure */
/* Instance variable table structure */
typedef
struct
iv_tbl
{
typedef
struct
iv_tbl
{
size_
t
size
,
alloc
;
in
t
size
,
alloc
;
mrb_value
*
ptr
;
mrb_value
*
ptr
;
}
iv_tbl
;
}
iv_tbl
;
...
@@ -41,8 +41,8 @@ static void iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val);
...
@@ -41,8 +41,8 @@ static void iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val);
static
void
static
void
iv_rehash
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
iv_rehash
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
{
{
size_
t
old_alloc
=
t
->
alloc
;
in
t
old_alloc
=
t
->
alloc
;
size_
t
new_alloc
=
old_alloc
+
4
;
in
t
new_alloc
=
old_alloc
+
4
;
mrb_value
*
old_ptr
=
t
->
ptr
;
mrb_value
*
old_ptr
=
t
->
ptr
;
khash_power2
(
new_alloc
);
khash_power2
(
new_alloc
);
...
@@ -55,7 +55,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
...
@@ -55,7 +55,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
old_ptr
[
old_alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
old_ptr
[
old_alloc
];
mrb_value
*
vals
=
old_ptr
;
mrb_value
*
vals
=
old_ptr
;
for
(
size_
t
i
=
0
;
i
<
old_alloc
;
i
++
)
{
for
(
in
t
i
=
0
;
i
<
old_alloc
;
i
++
)
{
if
(
IV_KEY_P
(
keys
[
i
]))
{
if
(
IV_KEY_P
(
keys
[
i
]))
{
iv_put
(
mrb
,
t
,
keys
[
i
],
vals
[
i
]);
iv_put
(
mrb
,
t
,
keys
[
i
],
vals
[
i
]);
}
}
...
@@ -67,8 +67,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
...
@@ -67,8 +67,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
static
void
static
void
iv_put
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
val
)
iv_put
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
val
)
{
{
size_t
hash
,
pos
,
start
;
int
hash
,
pos
,
start
,
dpos
=
-
1
;
int
dpos
=
-
1
;
if
(
t
==
NULL
)
return
;
if
(
t
==
NULL
)
return
;
if
(
t
->
alloc
==
0
)
{
if
(
t
->
alloc
==
0
)
{
...
@@ -112,10 +111,10 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -112,10 +111,10 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
}
}
/* Get a value for a symbol from the instance variable table. */
/* Get a value for a symbol from the instance variable table. */
static
size_
t
static
in
t
iv_get
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
iv_get
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
{
{
size_
t
hash
,
pos
,
start
;
in
t
hash
,
pos
,
start
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
...
@@ -145,7 +144,7 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -145,7 +144,7 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
static
mrb_bool
static
mrb_bool
iv_del
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
iv_del
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_sym
sym
,
mrb_value
*
vp
)
{
{
size_
t
hash
,
pos
,
start
;
in
t
hash
,
pos
,
start
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
...
@@ -177,7 +176,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -177,7 +176,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
static
void
static
void
iv_foreach
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_iv_foreach_func
*
func
,
void
*
p
)
iv_foreach
(
mrb_state
*
mrb
,
iv_tbl
*
t
,
mrb_iv_foreach_func
*
func
,
void
*
p
)
{
{
size_
t
i
;
in
t
i
;
if
(
t
==
NULL
)
return
;
if
(
t
==
NULL
)
return
;
if
(
t
->
alloc
==
0
)
return
;
if
(
t
->
alloc
==
0
)
return
;
...
@@ -201,7 +200,7 @@ static size_t
...
@@ -201,7 +200,7 @@ static size_t
iv_size
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
iv_size
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
{
{
if
(
t
==
NULL
)
return
0
;
if
(
t
==
NULL
)
return
0
;
return
t
->
size
;
return
(
size_t
)
t
->
size
;
}
}
/* Copy the instance variable table. */
/* Copy the instance variable table. */
...
@@ -209,7 +208,7 @@ static iv_tbl*
...
@@ -209,7 +208,7 @@ static iv_tbl*
iv_copy
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
iv_copy
(
mrb_state
*
mrb
,
iv_tbl
*
t
)
{
{
iv_tbl
*
t2
;
iv_tbl
*
t2
;
size_
t
i
;
in
t
i
;
if
(
t
==
NULL
)
return
NULL
;
if
(
t
==
NULL
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
...
@@ -486,7 +485,7 @@ mrb_value
...
@@ -486,7 +485,7 @@ mrb_value
mrb_obj_iv_inspect
(
mrb_state
*
mrb
,
struct
RObject
*
obj
)
mrb_obj_iv_inspect
(
mrb_state
*
mrb
,
struct
RObject
*
obj
)
{
{
iv_tbl
*
t
=
obj
->
iv
;
iv_tbl
*
t
=
obj
->
iv
;
size_
t
len
=
iv_size
(
mrb
,
t
);
in
t
len
=
iv_size
(
mrb
,
t
);
if
(
len
>
0
)
{
if
(
len
>
0
)
{
const
char
*
cn
=
mrb_obj_classname
(
mrb
,
mrb_obj_value
(
obj
));
const
char
*
cn
=
mrb_obj_classname
(
mrb
,
mrb_obj_value
(
obj
));
...
@@ -660,7 +659,7 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v)
...
@@ -660,7 +659,7 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v)
while
(
c
)
{
while
(
c
)
{
iv_tbl
*
t
=
c
->
iv
;
iv_tbl
*
t
=
c
->
iv
;
size_
t
pos
=
iv_get
(
mrb
,
t
,
sym
,
NULL
);
in
t
pos
=
iv_get
(
mrb
,
t
,
sym
,
NULL
);
if
(
pos
)
{
if
(
pos
)
{
mrb_check_frozen
(
mrb
,
c
);
mrb_check_frozen
(
mrb
,
c
);
...
...
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