Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9167f3a13008
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 149a52eddd18
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 1, 2016

  1. Call site caching for File.

    headius committed Aug 1, 2016
    Copy the full SHA
    2101092 View commit details
  2. Copy the full SHA
    149a52e View commit details
Showing with 26 additions and 9 deletions.
  1. +14 −7 core/src/main/java/org/jruby/RubyFile.java
  2. +2 −2 core/src/main/java/org/jruby/RubyString.java
  3. +10 −0 core/src/main/java/org/jruby/runtime/JavaSites.java
21 changes: 14 additions & 7 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@
import jnr.posix.util.Platform;
import org.jruby.runtime.Block;
import org.jruby.runtime.ClassIndex;
import org.jruby.runtime.JavaSites;
import org.jruby.runtime.JavaSites.FileSites;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import static org.jruby.runtime.Visibility.*;
@@ -346,7 +348,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
}

if (args.length > 0 && args.length <= 3) {
IRubyObject fd = TypeConverter.convertToTypeWithCheck(args[0], context.runtime.getFixnum(), "to_int");
IRubyObject fd = TypeConverter.convertToTypeWithCheck(context, args[0], context.runtime.getFixnum(), sites(context).to_int_checked);
if (!fd.isNil()) {
if (args.length == 1) {
return super.initialize(context, fd, block);
@@ -1105,8 +1107,8 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb
long[] mtimeval = null;

if (args[0] != runtime.getNil() || args[1] != runtime.getNil()) {
atimeval = extractTimeval(runtime, args[0]);
mtimeval = extractTimeval(runtime, args[1]);
atimeval = extractTimeval(context, args[0]);
mtimeval = extractTimeval(context, args[1]);
}

for (int i = 2, j = args.length; i < j; i++) {
@@ -1284,7 +1286,7 @@ protected IRubyObject openFile(ThreadContext context, IRubyObject args[]) {
}
case 4:
if (!args[3].isNil()) {
options = TypeConverter.convertToTypeWithCheck(args[3], context.runtime.getHash(), "to_hash");
options = TypeConverter.convertToTypeWithCheck(context, args[3], context.runtime.getHash(), sites(context).to_hash_checked);
if (options.isNil()) {
throw runtime.newArgumentError("wrong number of arguments (4 for 1..3)");
}
@@ -1336,7 +1338,8 @@ public IRubyObject fileOpenGeneric(ThreadContext context, IRubyObject filename,
public static RubyString get_path(ThreadContext context, IRubyObject path) {
if (path instanceof RubyString) return (RubyString) path;

if (path.respondsTo("to_path")) path = path.callMethod(context, "to_path");
FileSites sites = sites(context);
if (sites.respond_to_to_path.respondsTo(context, path, path, true)) path = sites.to_path.call(context, path, path);

return filePathConvert(context, path.convertToString());
}
@@ -1506,7 +1509,7 @@ static String adjustRootPathOnWindows(Ruby runtime, String path, String dir) {
* Extract a timeval (an array of 2 longs: seconds and microseconds from epoch) from
* an IRubyObject.
*/
private static long[] extractTimeval(Ruby runtime, IRubyObject value) {
private static long[] extractTimeval(ThreadContext context, IRubyObject value) {
long[] timeval = new long[2];

if (value instanceof RubyFloat) {
@@ -1521,7 +1524,7 @@ private static long[] extractTimeval(Ruby runtime, IRubyObject value) {
if (value instanceof RubyTime) {
time = ((RubyTime) value);
} else {
time = (RubyTime) TypeConverter.convertToType(value, runtime.getTime(), "to_time", true);
time = (RubyTime) TypeConverter.convertToType(context, value, context.runtime.getTime(), sites(context).to_time_checked, true);
}
timeval[0] = Platform.IS_32_BIT ? RubyNumeric.num2int(time.to_i()) : RubyNumeric.num2long(time.to_i());
timeval[1] = Platform.IS_32_BIT ? RubyNumeric.num2int(time.usec()) : RubyNumeric.num2long(time.usec());
@@ -2094,6 +2097,10 @@ private static IRubyObject truncateCommon(ThreadContext context, IRubyObject rec
return RubyFixnum.zero(runtime);
}

private static FileSites sites(ThreadContext context) {
return context.sites.File;
}

@Deprecated
public IRubyObject initialize19(IRubyObject[] args, Block block) {
return initialize(null, args, block);
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -2389,7 +2389,7 @@ public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, Block blo
@JRubyMethod(name = "sub!", reads = BACKREF, writes = BACKREF)
public IRubyObject sub_bang19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
Ruby runtime = context.runtime;
IRubyObject hash = TypeConverter.convertToTypeWithCheck(arg1, runtime.getHash(), "to_hash");
IRubyObject hash = TypeConverter.convertToTypeWithCheck(context, arg1, runtime.getHash(), sites(context).to_hash_checked);
frozenCheck();

RubyRegexp regexp = arg0 instanceof RubyRegexp ? (RubyRegexp) arg0 :
@@ -2546,7 +2546,7 @@ public IRubyObject gsub_bang19(ThreadContext context, IRubyObject arg0, IRubyObj

private IRubyObject gsub19(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block, final boolean bang) {
Ruby runtime = context.runtime;
IRubyObject tryHash = TypeConverter.convertToTypeWithCheck(arg1, runtime.getHash(), "to_hash");
IRubyObject tryHash = TypeConverter.convertToTypeWithCheck(context, arg1, runtime.getHash(), sites(context).to_hash_checked);

final RubyHash hash;
final RubyString str;
10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public class JavaSites {
public final EnumerableSites Enumerable = new EnumerableSites();
public final ComparableSites Comparable = new ComparableSites();
public final IOSites IO = new IOSites();
public final FileSites File = new FileSites();
public final TypeConverterSites TypeConverter = new TypeConverterSites();
public final HelpersSites Helpers = new HelpersSites();
public final IRRuntimeHelpersSites IRRuntimeHelpers = new IRRuntimeHelpersSites();
@@ -129,6 +130,7 @@ public static class StringSites {
public final CallSite op_minus = new FunctionalCachingCallSite("-");
public final CallSite op_lshift = new FunctionalCachingCallSite("<<");
public final CallSite op_and = new FunctionalCachingCallSite("&");
public final CheckedSites to_hash_checked = new CheckedSites("to_hash");

public final Ruby.RecursiveFunctionEx recursive_cmp = new Ruby.RecursiveFunctionEx<IRubyObject>() {
@Override
@@ -290,6 +292,14 @@ public static class IOSites {
public final RespondToCallSite respond_to_to_hash = new RespondToCallSite("to_hash");
}

public static class FileSites {
public final CallSite to_path = new FunctionalCachingCallSite("to_path");
public final RespondToCallSite respond_to_to_path = new RespondToCallSite("to_path");
public final CheckedSites to_time_checked = new CheckedSites("to_time");
public final CheckedSites to_int_checked = new CheckedSites("to_int");
public final CheckedSites to_hash_checked = new CheckedSites("to_hash");
}

public static class TypeConverterSites {
public final CheckedSites to_f_checked = new CheckedSites("to_f");
public final CheckedSites to_int_checked = new CheckedSites("to_int");