2828
2929import org .jruby .anno .JRubyClass ;
3030import org .jruby .anno .JRubyMethod ;
31- import org .jruby .api .Create ;
3231import org .jruby .runtime .Block ;
3332import org .jruby .runtime .CallSite ;
3433import org .jruby .runtime .Helpers ;
@@ -215,7 +214,7 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
215214 if (b instanceof RubyFixnum && e .isNil () && s instanceof RubyFixnum ) {
216215 long i = fix2long (b );
217216 long unit = fix2long (s );
218- ary = newArray (context , n );
217+ ary = newRawArray (context , n );
219218 while (n > 0 && fixable (context .runtime , i )) {
220219 ary .append (context , asFixnum (context , i ));
221220 i += unit ; /* FIXABLE + FIXABLE never overflow; */
@@ -230,7 +229,7 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
230229 }
231230 }
232231
233- return ary ;
232+ return ary . finishRawArray ( context ) ;
234233 } else if (b instanceof RubyFixnum && e instanceof RubyFixnum && s instanceof RubyFixnum ) {
235234 long i = fix2long (b );
236235 long end = fix2long (e );
@@ -242,7 +241,7 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
242241
243242 len = end - i ;
244243 if (len < 0 ) len = 0 ;
245- ary = newArray (context , Math .min (n , len ));
244+ ary = newRawArray (context , Math .min (n , len ));
246245 while (n > 0 && i < end ) {
247246 ary .append (context , asFixnum (context , i ));
248247 if (i + unit < i ) break ;
@@ -254,7 +253,7 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
254253
255254 len = i - end ;
256255 if (len < 0 ) len = 0 ;
257- ary = newArray (context , Math .min (n , len ));
256+ ary = newRawArray (context , Math .min (n , len ));
258257 while (n > 0 && i > end ) {
259258 ary .append (context , asFixnum (context , i ));
260259 if (i + unit > i ) break ;
@@ -263,7 +262,7 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
263262 }
264263 }
265264
266- return ary ;
265+ return ary . finishRawArray ( context ) ;
267266 } else if (b instanceof RubyFloat || e instanceof RubyFloat || s instanceof RubyFloat ) {
268267 /* generate values like ruby_float_step */
269268
@@ -276,25 +275,25 @@ public IRubyObject first(ThreadContext context, IRubyObject num) {
276275 if (n > len ) n = (long )len ;
277276
278277 if (Double .isInfinite (unit )) {
279- ary = len > 0 ?
280- newArray (context , 1 ). append ( context , asFloat (context , beg )) :
278+ return len > 0 ?
279+ newArray (context , asFloat (context , beg )) :
281280 newEmptyArray (context );
282281 } else if (unit == 0 ) {
283282 IRubyObject val = asFloat (context , beg );
284- ary = newArray (context , n );
283+ ary = newRawArray (context , n );
285284 for (i = 0 ; i < len ; ++i ) {
286285 ary .append (context , val );
287286 }
288287 } else {
289- ary = newArray (context , n );
288+ ary = newRawArray (context , n );
290289 for (i = 0 ; i < n ; ++i ) {
291290 double d = i * unit + beg ;
292291 if (unit >= 0 ? end < d : d < end ) d = end ;
293292 ary .append (context , asFloat (context , d ));
294293 }
295294 }
296295
297- return ary ;
296+ return ary . finishRawArray ( context ) ;
298297 }
299298
300299 return Helpers .invokeSuper (context , this , context .runtime .getEnumerator (), "first" , num , Block .NULL_BLOCK );
@@ -476,15 +475,15 @@ public IRubyObject last(ThreadContext context, IRubyObject num) {
476475 long n = numericToLong (context , nv );
477476 if (n < 0 ) throw argumentError (context , "negative array size" );
478477
479- var ary = newArray (context , n );
478+ var ary = newRawArray (context , n );
480479 b = ((RubyNumeric )last ).op_minus (context , Numeric .f_mul (context , s , nv ));
481480 while (n > 0 ) {
482481 b = ((RubyNumeric )b ).op_plus (context , s );
483482 ary .append (context , b );
484483 --n ;
485484 }
486485
487- return ary ;
486+ return ary . finishRawArray ( context ) ;
488487 }
489488
490489 @ JRubyMethod
0 commit comments