Skip to content

Commit 1393e2b

Browse files
committed
Extract readBuf
1 parent efe8351 commit 1393e2b

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,11 +1110,7 @@ private IRubyObject readCommon(ThreadContext context, int argc, IRubyObject arg0
11101110
final RubyString string;
11111111
switch (argc) {
11121112
case 2:
1113-
str = arg1;
1114-
if (!str.isNil()) {
1115-
str = str.convertToString();
1116-
modifyString((RubyString) str);
1117-
}
1113+
str = readBuf(arg1);
11181114
case 1:
11191115
if (!arg0.isNil()) {
11201116
len = RubyNumeric.fix2int(arg0);
@@ -1206,11 +1202,7 @@ private RubyString preadCommon(ThreadContext context, int argc, IRubyObject arg0
12061202

12071203
switch (argc) {
12081204
case 3:
1209-
str = arg2;
1210-
if (!str.isNil()) {
1211-
str = str.convertToString();
1212-
modifyString((RubyString) str);
1213-
}
1205+
str = readBuf(arg2);
12141206
case 2:
12151207
len = RubyNumeric.fix2int(arg0);
12161208
if (!arg0.isNil()) {
@@ -1702,6 +1694,14 @@ private static IRubyObject substrString(RubyString ch, IRubyObject str, Ruby run
17021694
return str;
17031695
}
17041696

1697+
private static IRubyObject readBuf(IRubyObject str) {
1698+
if (!str.isNil()) {
1699+
str = str.convertToString();
1700+
modifyString((RubyString) str);
1701+
}
1702+
return str;
1703+
}
1704+
17051705
// MRI: strio_write
17061706
private long stringIOWrite(ThreadContext context, Ruby runtime, IRubyObject arg) {
17071707
checkWritable();

0 commit comments

Comments
 (0)