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
312b2c7b
Commit
312b2c7b
authored
Jul 07, 2012
by
Masaki Muranaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize range check.
parent
8268ba27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
src/array.c
src/array.c
+8
-4
No files found.
src/array.c
View file @
312b2c7b
...
...
@@ -566,10 +566,12 @@ mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val) /* rb_ary_s
ary_modify
(
mrb
,
a
);
/* range check */
if
(
n
<
0
)
n
+=
a
->
len
;
if
(
n
<
0
)
{
n
+=
a
->
len
;
if
(
n
<
0
)
{
mrb_raise
(
mrb
,
E_INDEX_ERROR
,
"index %ld out of array"
,
n
-
a
->
len
);
}
}
if
(
a
->
len
<=
(
int
)
n
)
{
if
(
a
->
aux
.
capa
<=
(
int
)
n
)
ary_expand_capa
(
mrb
,
a
,
n
+
1
);
...
...
@@ -592,10 +594,12 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
ary_modify
(
mrb
,
a
);
/* range check */
if
(
head
<
0
)
head
+=
a
->
len
;
if
(
head
<
0
)
{
head
+=
a
->
len
;
if
(
head
<
0
)
{
mrb_raise
(
mrb
,
E_INDEX_ERROR
,
"index is out of array"
);
}
}
tail
=
head
+
len
;
/* size check */
...
...
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