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: 242c3a5ed53c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8ac17f336a96
Choose a head ref
  • 8 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 26, 2017

  1. Copy the full SHA
    5fd6bab View commit details
  2. Copy the full SHA
    9ec21eb View commit details
  3. Copy the full SHA
    377904b View commit details
  4. [tune] RubyFile internals - fix toString; faster replace; don't catch…

    … much
    
    .. also refactored some jar entry fetching - just to notice that its not used
    kares committed Jun 26, 2017
    Copy the full SHA
    9f2f33f View commit details
  5. Copy the full SHA
    73747d2 View commit details
  6. Copy the full SHA
    083427e View commit details
  7. Copy the full SHA
    9056206 View commit details
  8. Copy the full SHA
    8ac17f3 View commit details
Showing with 127 additions and 114 deletions.
  1. +5 −5 core/src/main/java/org/jruby/RubyDir.java
  2. +29 −27 core/src/main/java/org/jruby/RubyFile.java
  3. +93 −82 core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyDir.java
Original file line number Diff line number Diff line change
@@ -315,7 +315,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
realPath = dir.canonicalPath();
}

IRubyObject result = null;
IRubyObject result;
if (block.isGiven()) {
// FIXME: Don't allow multiple threads to do this at once
runtime.setCurrentDirectory(realPath);
@@ -790,11 +790,11 @@ public static IRubyObject getHomeDirectoryPath(ThreadContext context, String use
String passwd;
try {
FileInputStream stream = new FileInputStream("/etc/passwd");
int totalBytes = stream.available();
byte[] bytes = new byte[totalBytes];
stream.read(bytes);
int readBytes = stream.available();
byte[] bytes = new byte[readBytes];
readBytes = stream.read(bytes);
stream.close();
passwd = new String(bytes);
passwd = new String(bytes, 0, readBytes);
} catch (IOException ioe) {
return runtime.getNil();
}
56 changes: 29 additions & 27 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -493,11 +493,11 @@ public IRubyObject truncate(ThreadContext context, IRubyObject len) {
public IRubyObject inspect() {
StringBuilder val = new StringBuilder();
val.append("#<File:").append(getPath());
if(!openFile.isOpen()) {
if (!openFile.isOpen()) {
val.append(" (closed)");
}
val.append('>');
return getRuntime().newString(val.toString());
return RubyString.newString(getRuntime(), val);
}

private static final String URI_PREFIX_STRING = "^(uri|jar|file|classpath):([^:/]{2,}:([^:/]{2,}:)?)?";
@@ -670,7 +670,7 @@ public static String dirname(ThreadContext context, String jfilename) {
}
String name = jfilename;
if (altSeparator != null) {
name = jfilename.replace(altSeparator, separator);
name = replace(jfilename, altSeparator, separator);
}
int minPathLength = 1;
boolean trimmedSlashes = false;
@@ -1447,16 +1447,15 @@ public static JRubyFile file(IRubyObject pathOrFile) {

@Override
public String toString() {
return "RubyFile(" + openFile.getPath() + ", " + openFile.getMode();
return "RubyFile(" + openFile.getPath() + ", " + openFile.getMode() + ')';
}

@Deprecated // private
public static ZipEntry getFileEntry(ZipFile zf, String path) throws IOException {
ZipEntry entry = zf.getEntry(path);
private static ZipEntry getFileEntry(ZipFile jar, String path, final String prefixForNoEntry) throws IOException {
ZipEntry entry = jar.getEntry(path);
if (entry == null) {
// try canonicalizing the path to eliminate . and .. (JRUBY-4760, JRUBY-4879)
String prefix = new File(".").getCanonicalPath();
entry = zf.getEntry(new File(path).getCanonicalPath().substring(prefix.length() + 1).replaceAll("\\\\", "/"));
path = new File(path).getCanonicalPath().substring(prefixForNoEntry.length() + 1);
entry = jar.getEntry(path.replaceAll("\\\\", "/"));
}
return entry;
}
@@ -1466,21 +1465,21 @@ public static ZipEntry getDirOrFileEntry(String jar, String path) throws IOExcep
return getDirOrFileEntry(new JarFile(jar), path);
}

@Deprecated // private
public static ZipEntry getDirOrFileEntry(ZipFile zf, String path) throws IOException {
@Deprecated // not-used
public static ZipEntry getDirOrFileEntry(ZipFile jar, String path) throws IOException {
String dirPath = path + '/';
ZipEntry entry = zf.getEntry(dirPath); // first try as directory
ZipEntry entry = jar.getEntry(dirPath); // first try as directory
if (entry == null) {
if (dirPath.length() == 1) {
return new ZipEntry(dirPath);
}
// try canonicalizing the path to eliminate . and .. (JRUBY-4760, JRUBY-4879)
String prefix = new File(".").getCanonicalPath();
entry = zf.getEntry(new File(dirPath).getCanonicalPath().substring(prefix.length() + 1).replaceAll("\\\\", "/"));
final String prefix = new File(".").getCanonicalPath();
entry = jar.getEntry(new File(dirPath).getCanonicalPath().substring(prefix.length() + 1).replaceAll("\\\\", "/"));

// JRUBY-6119
if (entry == null) {
Enumeration<? extends ZipEntry> entries = zf.entries();
Enumeration<? extends ZipEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
String zipEntry = entries.nextElement().getName();
if (zipEntry.startsWith(dirPath)) {
@@ -1489,9 +1488,8 @@ public static ZipEntry getDirOrFileEntry(ZipFile zf, String path) throws IOExcep
}
}

if (entry == null) {
// try as file
entry = getFileEntry(zf, path);
if (entry == null) { // try as file
entry = getFileEntry(jar, path, prefix);
}
}
return entry;
@@ -1807,11 +1805,9 @@ private static IRubyObject expandPathInternal(ThreadContext context, IRubyObject
}

private static RubyString concatStrings(final Ruby runtime, String s1, String s2, String s3, Encoding enc) {
return RubyString.newString(runtime,
new StringBuilder(s1.length() + s2.length() + s3.length()).
append(s1).append(s2).append(s3).toString(),
enc
);
StringBuilder str = new StringBuilder(s1.length() + s2.length() + s3.length())
.append(s1).append(s2).append(s3);
return new RubyString(runtime, runtime.getString(), str, enc);
}

private static String canonicalizePath(String path) {
@@ -1842,8 +1838,7 @@ public static String[] splitURI(String path) {
URL u = new URL(pathWithoutJarPrefix);
String pathPart = u.getPath();
return new String[] {path.substring(0, path.indexOf(pathPart)), pathPart};
} catch (Exception e2) {
}
} catch (MalformedURLException e2) { /* ignore */ }
}
}
return null;
@@ -1919,7 +1914,7 @@ public static String expandUserPath(ThreadContext context, String path, final bo
* @param stringToCheck
* @return
*/
private static String countSlashes( String stringToCheck ) {
private static String countSlashes(String stringToCheck) {
// Count number of extra slashes in the beginning of the string.
int slashCount = 0;
for (int i = 0; i < stringToCheck.length(); i++) {
@@ -2089,7 +2084,7 @@ private static StringBuilder joinImplInspecting(final String separator,
}
}

// FIXME: MRI and JRuby are both broken here since it does not actually look up
// NOTE: MRI and JRuby are both broken here since it does not actually look up
// File::{SEPARATOR,ALT_SEPARATOR} but merely hardcodes depending on whether we are on Windows.
private static boolean isDirSeparator(char c) {
return c == '/' || Platform.IS_WINDOWS && c == '\\';
@@ -2142,6 +2137,13 @@ private static int lastIndexOf(final CharSequence str, final char c, int index)
return -1;
}

private static String replace(final String str, CharSequence target, CharSequence replace) {
if (target.length() == 1 && replace.length() == 1) {
return str.replace(target.charAt(0), replace.charAt(0));
}
return str.replace(target, replace);
}

private static IRubyObject truncateCommon(ThreadContext context, IRubyObject recv, IRubyObject arg1, IRubyObject arg2) {
RubyString filename = arg1.convertToString(); // TODO: SafeStringValue here
Ruby runtime = context.runtime;
Loading