-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Incoming #4631
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
Incoming #4631
Conversation
For every call to the read() function the internal buffer was copied into a new buffer (minus the bytes copied into the result buffer). When the internal buffer is large enough, this severely affects performance, especially when read_line() is used which calls read_byte() (which calls read()) for each read byte. For line oriented I/O this wasn't all that bad, because the internal buffers usually never were very big. The effect is much more visible once the buffer grows larger. Now we always first look into the internal buffer and copy as many bytes as possible (and desired) into the result buffer. If we need more, we call the socket read function and use the result as the new internal buffer, then continue to copy from the (new) internal buffer, and so on.
No need to allocate an additional vector. Instead directly push into the string.
For future reference, you can aim pull requests at the incoming branch by clicking on the black box that says |
ok! |
Thanks! Merged. |
Doesn't the fn main() {
// old version
let b = ~[0xC3u8, 0xA5];
io::println(str::from_bytes(b)); // prints 'å'
// new version
let mut s = ~"";
str::push_char(&mut s,0xC3 as char);
str::push_char(&mut s,0xA5 as char);
io::println(s); // prints 'Ã¥'
} |
@dbaupp Yes, you are right. I will add a test and revert. |
I think instead it would be save to do at the end |
Automatic Rustup
Automatic Rustup
Please see especially the rewrite of TcpSocketBuf.read which fixes a performance bug.