Skip to content

Commit 70d7ef9

Browse files
committed
Update comment explaining why we read the bytes ourselves
* The encoding is no longer an issue, TruffleFile.FileTypeDetector solves that.
1 parent b0e295e commit 70d7ef9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public RubySource loadFile(Env env, String path) throws IOException {
6464
}
6565

6666
/*
67-
* We must read the file bytes ourselves - otherwise Truffle will read them, assume they're UTF-8, and we will
68-
* not be able to re-interpret the encoding later without the risk of the values being corrupted by being
69-
* passed through UTF-8.
67+
* We read the file's bytes ourselves because the lexer works on bytes and Truffle only gives us a CharSequence.
68+
* We could convert the CharSequence back to bytes, but that's more expensive than just reading the bytes once
69+
* and pass them down to the lexer and to the Source.
7070
*/
7171

7272
final byte[] sourceBytes = file.readAllBytes();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public RubySource loadFromFile(Env env, RubyNode currentNode, String path) throw
8585
fileLoader.ensureReadable(file);
8686

8787
/*
88-
* We must read the file bytes ourselves - otherwise Truffle will read them, assume they're UTF-8, and we will
89-
* not be able to re-interpret the encoding later without the risk of the values being corrupted by being
90-
* passed through UTF-8.
88+
* We read the file's bytes ourselves because the lexer works on bytes and Truffle only gives us a CharSequence.
89+
* We could convert the CharSequence back to bytes, but that's more expensive than just reading the bytes once
90+
* and pass them down to the lexer and to the Source.
9191
*/
9292

9393
byte[] sourceBytes = file.readAllBytes();

0 commit comments

Comments
 (0)