summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-11 08:26:21 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-11 08:26:21 (GMT)
commit83ac2dfe0fdd33edcc4db40ebb75a81f342ce19e (patch)
tree4837417ac220edb46a54f28a4626464af32e55b6 /vm_insnhelper.c
parentf41b4b1bfb4a29f8648a74f124bd0ca60307aaf8 (diff)
vm_insnhelper.c: search in the indexing order
* vm_insnhelper.c (vm_opt_newarray_max, vm_opt_newarray_min): search in the indexing order, as well as usual methods. [ruby-core:84821] [Bug #14350] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index c66ed6d..f68d34d 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3206,16 +3206,15 @@ vm_opt_newarray_max(rb_num_t num, const VALUE *ptr)
}
else {
struct cmp_opt_data cmp_opt = { 0, 0 };
- VALUE result = Qundef;
+ VALUE result = *ptr;
rb_num_t i = num - 1;
- result = ptr[i];
while (i-- > 0) {
- const VALUE v = ptr[i];
- if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) > 0) {
+ const VALUE v = *++ptr;
+ if (OPTIMIZED_CMP(v, result, cmp_opt) > 0) {
result = v;
}
}
- return result == Qundef ? Qnil : result;
+ return result;
}
}
else {
@@ -3233,16 +3232,15 @@ vm_opt_newarray_min(rb_num_t num, const VALUE *ptr)
}
else {
struct cmp_opt_data cmp_opt = { 0, 0 };
- VALUE result = Qundef;
+ VALUE result = *ptr;
rb_num_t i = num - 1;
- result = ptr[i];
while (i-- > 0) {
- const VALUE v = ptr[i];
- if (result == Qundef || OPTIMIZED_CMP(v, result, cmp_opt) < 0) {
+ const VALUE v = *++ptr;
+ if (OPTIMIZED_CMP(v, result, cmp_opt) < 0) {
result = v;
}
}
- return result == Qundef ? Qnil : result;
+ return result;
}
}
else {