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
7b84fd4c
Unverified
Commit
7b84fd4c
authored
Dec 11, 2021
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
variable.c: resurrect `size` member in `iv_tbl`.
The existence of this member reduces memory and execution time.
parent
786156d4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
src/variable.c
src/variable.c
+11
-3
No files found.
src/variable.c
View file @
7b84fd4c
...
@@ -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
alloc
;
size_t
size
,
alloc
;
mrb_value
*
ptr
;
mrb_value
*
ptr
;
}
iv_tbl
;
}
iv_tbl
;
...
@@ -47,6 +47,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
...
@@ -47,6 +47,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t)
khash_power2
(
new_alloc
);
khash_power2
(
new_alloc
);
if
(
old_alloc
==
new_alloc
)
return
;
if
(
old_alloc
==
new_alloc
)
return
;
t
->
size
=
0
;
t
->
alloc
=
new_alloc
;
t
->
alloc
=
new_alloc
;
t
->
ptr
=
(
mrb_value
*
)
mrb_calloc
(
mrb
,
sizeof
(
mrb_value
)
+
sizeof
(
mrb_sym
),
new_alloc
);
t
->
ptr
=
(
mrb_value
*
)
mrb_calloc
(
mrb
,
sizeof
(
mrb_value
)
+
sizeof
(
mrb_sym
),
new_alloc
);
if
(
old_alloc
==
0
)
return
;
if
(
old_alloc
==
0
)
return
;
...
@@ -84,6 +85,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -84,6 +85,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
return
;
return
;
}
}
else
if
(
key
==
IV_EMPTY
)
{
else
if
(
key
==
IV_EMPTY
)
{
t
->
size
++
;
keys
[
pos
]
=
sym
;
keys
[
pos
]
=
sym
;
vals
[
pos
]
=
val
;
vals
[
pos
]
=
val
;
return
;
return
;
...
@@ -94,6 +96,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
...
@@ -94,6 +96,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val)
pos
=
(
pos
+
1
)
&
(
t
->
alloc
-
1
);
pos
=
(
pos
+
1
)
&
(
t
->
alloc
-
1
);
if
(
pos
==
start
)
{
/* not found */
if
(
pos
==
start
)
{
/* not found */
if
(
dpos
>=
0
)
{
if
(
dpos
>=
0
)
{
t
->
size
++
;
keys
[
dpos
]
=
sym
;
keys
[
dpos
]
=
sym
;
vals
[
dpos
]
=
val
;
vals
[
dpos
]
=
val
;
return
;
return
;
...
@@ -115,6 +118,7 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -115,6 +118,7 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
size
==
0
)
return
FALSE
;
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_value
*
vals
=
t
->
ptr
;
mrb_value
*
vals
=
t
->
ptr
;
...
@@ -144,6 +148,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -144,6 +148,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
==
NULL
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
alloc
==
0
)
return
FALSE
;
if
(
t
->
size
==
0
)
return
FALSE
;
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_value
*
vals
=
t
->
ptr
;
mrb_value
*
vals
=
t
->
ptr
;
...
@@ -153,6 +158,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
...
@@ -153,6 +158,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp)
mrb_sym
key
=
keys
[
pos
];
mrb_sym
key
=
keys
[
pos
];
if
(
key
==
sym
)
{
if
(
key
==
sym
)
{
if
(
vp
)
*
vp
=
vals
[
pos
];
if
(
vp
)
*
vp
=
vals
[
pos
];
t
->
size
--
;
keys
[
pos
]
=
IV_DELETED
;
keys
[
pos
]
=
IV_DELETED
;
return
TRUE
;
return
TRUE
;
}
}
...
@@ -174,6 +180,7 @@ iv_foreach(mrb_state *mrb, iv_tbl *t, mrb_iv_foreach_func *func, void *p)
...
@@ -174,6 +180,7 @@ iv_foreach(mrb_state *mrb, iv_tbl *t, mrb_iv_foreach_func *func, void *p)
if
(
t
==
NULL
)
return
;
if
(
t
==
NULL
)
return
;
if
(
t
->
alloc
==
0
)
return
;
if
(
t
->
alloc
==
0
)
return
;
if
(
t
->
size
==
0
)
return
;
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_value
*
vals
=
t
->
ptr
;
mrb_value
*
vals
=
t
->
ptr
;
...
@@ -193,7 +200,7 @@ static size_t
...
@@ -193,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
->
alloc
;
return
t
->
size
;
}
}
/* Copy the instance variable table. */
/* Copy the instance variable table. */
...
@@ -205,6 +212,7 @@ iv_copy(mrb_state *mrb, iv_tbl *t)
...
@@ -205,6 +212,7 @@ iv_copy(mrb_state *mrb, iv_tbl *t)
if
(
t
==
NULL
)
return
NULL
;
if
(
t
==
NULL
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
if
(
t
->
alloc
==
0
)
return
NULL
;
if
(
t
->
size
==
0
)
return
NULL
;
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_sym
*
keys
=
(
mrb_sym
*
)
&
t
->
ptr
[
t
->
alloc
];
mrb_value
*
vals
=
t
->
ptr
;
mrb_value
*
vals
=
t
->
ptr
;
...
...
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