Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147894210
D30548.id90286.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
964 B
Referenced Files
None
Subscribers
None
D30548.id90286.diff
View Options
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c
--- a/lib/libc/stdio/fread.c
+++ b/lib/libc/stdio/fread.c
@@ -99,6 +99,35 @@
fp->_r = 0;
total = resid;
p = buf;
+
+ /*
+ * If we're unbuffered we know that the buffer in fp is empty so
+ * we can read directly into buf. This is much faster than a
+ * series of one byte reads into fp->_nbuf.
+ */
+ if ((fp->_flags & __SNBF) != 0 && buf != NULL) {
+ while (resid > 0) {
+ /* set up the buffer */
+ fp->_bf._base = fp->_p = p;
+ fp->_bf._size = resid;
+
+ if (__srefill(fp)) {
+ /* no more input: return partial result */
+ count = (total - resid) / size;
+ break;
+ }
+ p += fp->_r;
+ resid -= fp->_r;
+ }
+
+ /* restore the old buffer (see __smakebuf) */
+ fp->_bf._base = fp->_p = fp->_nbuf;
+ fp->_bf._size = 1;
+ fp->_r = 0;
+
+ return (count);
+ }
+
while (resid > (r = fp->_r)) {
(void)memcpy((void *)p, (void *)fp->_p, (size_t)r);
fp->_p += r;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 15, 11:54 AM (2 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29715364
Default Alt Text
D30548.id90286.diff (964 B)
Attached To
Mode
D30548: fread: improve performance for unbuffered reads
Attached
Detach File
Event Timeline
Log In to Comment