Skip to content

Commit

Permalink
Showing 1 changed file with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.LoopConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreClass;
@@ -25,7 +26,6 @@
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.methods.UnsupportedOperationBehavior;

import java.math.BigInteger;

@CoreClass(name = "Integer")
@@ -127,41 +127,35 @@ public DynamicObject times(VirtualFrame frame, int n, NotProvided block) {
}

@Specialization
public Object times(VirtualFrame frame, int n, DynamicObject block) {
int count = 0;

public int times(VirtualFrame frame, int n, DynamicObject block,
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
int i = 0;
loopProfile.profileCounted(n);
try {
for (int i = 0; i < n; i++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

for (; loopProfile.inject(i < n); i++) {
yield(frame, block, i);
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
getRootNode().reportLoopCount(i);
}
}

return n;
}

@Specialization
public Object times(VirtualFrame frame, long n, DynamicObject block) {
int count = 0;

public long times(VirtualFrame frame, long n, DynamicObject block,
@Cached("createCountingProfile()") LoopConditionProfile loopProfile) {
long i = 0;
loopProfile.profileCounted(n);
try {
for (long i = 0; i < n; i++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

for (; loopProfile.inject(i < n); i++) {
yield(frame, block, i);
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
getRootNode().reportLoopCount(i < Integer.MAX_VALUE ? (int) i : Integer.MAX_VALUE);
}
}

0 comments on commit a67ade8

Please sign in to comment.