Skip to content

Commit 8a9f17c

Browse files
committed
Use transcoder to do textmode crlf translation on Windows.
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.
1 parent cd7f7e2 commit 8a9f17c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/src/main/java/org/jruby/util/io/OpenFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ public void finalize(ThreadContext context, boolean noraise) {
895895
// MRI: NEED_READCONV
896896
public boolean needsReadConversion() {
897897
return Platform.IS_WINDOWS ?
898-
(encs.enc2 != null || (encs.ecflags & ~EConvFlags.CRLF_NEWLINE_DECORATOR) != 0)
898+
(encs.enc2 != null || (encs.ecflags & ~EConvFlags.CRLF_NEWLINE_DECORATOR) != 0) || isTextMode()
899899
:
900900
(encs.enc2 != null || NEED_NEWLINE_DECORATOR_ON_READ());
901901
}
@@ -917,6 +917,10 @@ public void makeReadConversion(ThreadContext context, int size) {
917917
IRubyObject ecopts;
918918
byte[] sname, dname;
919919
ecflags = encs.ecflags & ~EConvFlags.NEWLINE_DECORATOR_WRITE_MASK;
920+
if (isTextMode() && Platform.IS_WINDOWS) {
921+
// we can't do O_TEXT so we always do CRLF translation on Windows
922+
ecflags = ecflags | EConvFlags.UNIVERSAL_NEWLINE_DECORATOR;
923+
}
920924
ecopts = encs.ecopts;
921925
if (encs.enc2 != null) {
922926
sname = encs.enc2.getName();

0 commit comments

Comments
 (0)