summaryrefslogtreecommitdiffhomepage
path: root/src/array.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-02-28 00:51:33 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-02-28 00:51:33 +0900
commit30ac4e55969889b7fab3acfdfe50de0822b18d9b (patch)
treef50c5c578228c4f55f20d70ae11871d96ead85dd /src/array.c
parented0797418c0ae4c06e15e5f8bcab6c6c4e8801af (diff)
parent88f3e5b2944e86d8b8cfbd677b4d0478d3935cd6 (diff)
downloadmruby-30ac4e55969889b7fab3acfdfe50de0822b18d9b.tar.gz
mruby-30ac4e55969889b7fab3acfdfe50de0822b18d9b.zip
Merge pull request #1758 from ksss/array-out-while
move check condition to outside in while block
Diffstat (limited to 'src/array.c')
-rw-r--r--src/array.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/array.c b/src/array.c
index 5ad90efff..7a268b894 100644
--- a/src/array.c
+++ b/src/array.c
@@ -185,13 +185,11 @@ ary_expand_capa(mrb_state *mrb, struct RArray *a, mrb_int len)
mrb_raise(mrb, E_ARGUMENT_ERROR, "array size too big");
}
+ if (capa == 0) {
+ capa = ARY_DEFAULT_LEN;
+ }
while (capa < len) {
- if (capa == 0) {
- capa = ARY_DEFAULT_LEN;
- }
- else {
- capa *= 2;
- }
+ capa *= 2;
}
if (capa > ARY_MAX_SIZE) capa = ARY_MAX_SIZE; /* len <= capa <= ARY_MAX_SIZE */