Skip to content

Commit

Permalink
[Truffle] Avoid an extra buffer allocation for File.readlink.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed May 29, 2015
1 parent 13d3bfb commit ac481dd
Showing 1 changed file with 2 additions and 5 deletions.
Expand Up @@ -241,17 +241,14 @@ public ReadlinkNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public int readlink(RubyString path, RubyBasicObject pointer, int bufsize) {
final String pathString = RubyEncoding.decodeUTF8(path.getByteList().getUnsafeBytes(), path.getByteList().getBegin(), path.getByteList().getRealSize());
final long address = PointerPrimitiveNodes.getPointer(pointer).address();

final byte[] buffer = new byte[bufsize];

final int result = posix().readlink(pathString, buffer, bufsize);
final int result = posix().readlink(pathString, address, bufsize);
if (result == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().errnoError(posix().errno(), this));
}

PointerPrimitiveNodes.getPointer(pointer).put(0, buffer, 0, buffer.length);

return result;
}

Expand Down

0 comments on commit ac481dd

Please sign in to comment.