Skip to content

Commit 239acde

Browse files
committed
Optimize isStdLibRubyOrCExtFile() check
1 parent a40992f commit 239acde

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/main/java/org/truffleruby/language/loader/FileLoader.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import java.io.File;
1313
import java.io.IOException;
14-
import java.util.Locale;
1514

1615
import com.oracle.truffle.api.nodes.Node;
1716
import org.graalvm.collections.Pair;
@@ -57,7 +56,6 @@ public static void ensureReadable(RubyContext context, TruffleFile file, Node cu
5756
}
5857
}
5958

60-
6159
public Pair<Source, TStringWithEncoding> loadFile(String path) throws IOException {
6260
if (context.getOptions().LOG_LOAD) {
6361
RubyLanguage.LOGGER.info("loading " + path);
@@ -93,7 +91,7 @@ public static TruffleFile getSafeTruffleFile(RubyLanguage language, RubyContext
9391
}
9492

9593
final TruffleFile home = language.getRubyHomeTruffleFile();
96-
if (file.startsWith(home) && isStdLibRubyOrCExtFile(home.relativize(file))) {
94+
if (file.startsWith(home.resolve("lib")) && isStdLibRubyOrCExtFile(file.getPath())) {
9795
return file;
9896
} else {
9997
try {
@@ -109,19 +107,8 @@ public static TruffleFile getSafeTruffleFile(RubyLanguage language, RubyContext
109107
}
110108
}
111109

112-
private static boolean isStdLibRubyOrCExtFile(TruffleFile relativePathFromHome) {
113-
final String fileName = relativePathFromHome.getName();
114-
if (fileName == null) {
115-
return false;
116-
}
117-
118-
final String lowerCaseFileName = fileName.toLowerCase(Locale.ROOT);
119-
if (!lowerCaseFileName.endsWith(TruffleRuby.EXTENSION) &&
120-
!lowerCaseFileName.endsWith(RubyLanguage.CEXT_EXTENSION)) {
121-
return false;
122-
}
123-
124-
return relativePathFromHome.startsWith("lib");
110+
private static boolean isStdLibRubyOrCExtFile(String path) {
111+
return path.endsWith(TruffleRuby.EXTENSION) || path.endsWith(RubyLanguage.CEXT_EXTENSION);
125112
}
126113

127114
Source buildSource(TruffleFile file, String path, TStringWithEncoding sourceTStringWithEncoding, boolean internal,

0 commit comments

Comments
 (0)