summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
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 d4f2c2a00c..0a2eb94753 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3186,16 +3186,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 {
@@ -3213,16 +3212,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 {