Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 14368 - rawRead performance #3127

Merged
merged 3 commits into from Apr 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions std/stdio.d
Expand Up @@ -723,9 +723,10 @@ $(D rawRead) always reads in binary mode on Windows.
*/
T[] rawRead(T)(T[] buffer)
{
import std.exception : enforce, errnoEnforce;
import std.exception : Exception, errnoEnforce;

enforce(buffer.length, "rawRead must take a non-empty buffer");
if (!buffer.length)
throw new Exception("rawRead must take a non-empty buffer");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this improving anything?

version(Windows)
{
immutable fd = ._fileno(_p.handle);
Expand All @@ -741,10 +742,15 @@ $(D rawRead) always reads in binary mode on Windows.
scope(exit) __fhnd_info[fd] = info;
}
}
immutable result =
immutable freadResult =
fread(buffer.ptr, T.sizeof, buffer.length, _p.handle);
errnoEnforce(!error);
return result ? buffer[0 .. result] : null;
assert (freadResult <= buffer.length); // fread return guarantee
if (freadResult != buffer.length) // error or eof
{
errnoEnforce(!error);
return buffer[0 .. freadResult];
}
return buffer;
}

unittest
Expand Down