Skip to content

Commit

Permalink
Use transcoder to do textmode crlf translation on Windows.
Browse files Browse the repository at this point in the history
MRI is able to avoid this overhead by using O_TEXT at the file
descriptor level, which automatically translates \r\n to/from \n
on reads and writes. Since we don't have control over the
underlying fd/handle across the board on Windows, we must use
universal newline translation in the transcoder subsystem to
emulate O_TEXT.

In the future we will probably want to explore crlf solutions that
have less overhead.
headius committed May 20, 2015
1 parent cd7f7e2 commit 8a9f17c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -895,7 +895,7 @@ public void finalize(ThreadContext context, boolean noraise) {
// MRI: NEED_READCONV
public boolean needsReadConversion() {
return Platform.IS_WINDOWS ?
(encs.enc2 != null || (encs.ecflags & ~EConvFlags.CRLF_NEWLINE_DECORATOR) != 0)
(encs.enc2 != null || (encs.ecflags & ~EConvFlags.CRLF_NEWLINE_DECORATOR) != 0) || isTextMode()
:
(encs.enc2 != null || NEED_NEWLINE_DECORATOR_ON_READ());
}
@@ -917,6 +917,10 @@ public void makeReadConversion(ThreadContext context, int size) {
IRubyObject ecopts;
byte[] sname, dname;
ecflags = encs.ecflags & ~EConvFlags.NEWLINE_DECORATOR_WRITE_MASK;
if (isTextMode() && Platform.IS_WINDOWS) {
// we can't do O_TEXT so we always do CRLF translation on Windows
ecflags = ecflags | EConvFlags.UNIVERSAL_NEWLINE_DECORATOR;
}
ecopts = encs.ecopts;
if (encs.enc2 != null) {
sname = encs.enc2.getName();

0 comments on commit 8a9f17c

Please sign in to comment.