Skip to content

Commit

Permalink
Make puts(str) zero-alloc.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 2, 2016
1 parent 466fee0 commit 223cbd5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -2519,22 +2519,30 @@ private static IRubyObject putsArray(ThreadContext context, IRubyObject maybeIO,

private static void putsSingle(ThreadContext context, Ruby runtime, IRubyObject maybeIO, IRubyObject arg, RubyString separator) {
ByteList line;
RubyString string;

if (arg.isNil()) {
line = getNilByteList(runtime);
string = null;
} else if (runtime.isInspecting(arg)) {
line = RECURSIVE_BYTELIST;
string = null;
} else if (arg instanceof RubyArray) {
inspectPuts(context, maybeIO, (RubyArray) arg);
return;
} else {
line = arg.asString().getByteList();
string = arg.asString();
line = string.getByteList();
}

write(context, maybeIO, line);
if (string != null) {
write(context, maybeIO, string);
} else {
write(context, maybeIO, line);
}

if (line.length() == 0 || !line.endsWith(separator.getByteList())) {
write(context, maybeIO, separator.getByteList());
write(context, maybeIO, separator);
}
}

Expand Down

0 comments on commit 223cbd5

Please sign in to comment.