pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/d1df227ba8ee848618d27b890b1408c3c5ca2b91

el="stylesheet" href="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Merge pull request #8484 from headius/array_optz · jruby/jruby@d1df227 · GitHub
Skip to content

Commit d1df227

Browse files
authored
Merge pull request #8484 from headius/array_optz
Various array optimizations
2 parents 9fdd654 + bfb53c8 commit d1df227

40 files changed

Lines changed: 603 additions & 438 deletions

core/src/main/java/org/jruby/RubyArithmeticSequence.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import org.jruby.anno.JRubyClass;
3030
import org.jruby.anno.JRubyMethod;
31-
import org.jruby.api.Create;
3231
import org.jruby.runtime.Block;
3332
import org.jruby.runtime.CallSite;
3433
import 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy