libstd: Remove mutable fields from flatpipes and io_util

This commit is contained in:
Patrick Walton 2013-05-02 22:44:03 -07:00
parent da2ac90812
commit 92d2ec4d32
2 changed files with 15 additions and 13 deletions

View File

@ -558,9 +558,11 @@ pub mod bytepipes {
}
}
// XXX: Remove `@mut` when this module is ported to the new I/O traits,
// which use `&mut self` properly.
pub struct PipeBytePort {
port: comm::Port<~[u8]>,
mut buf: ~[u8]
buf: @mut ~[u8]
}
pub struct PipeByteChan {
@ -569,13 +571,13 @@ pub mod bytepipes {
impl BytePort for PipeBytePort {
fn try_recv(&self, count: uint) -> Option<~[u8]> {
if vec::uniq_len(&const self.buf) >= count {
let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
self.buf = bytes.slice(count, bytes.len()).to_owned();
if vec::uniq_len(&const *self.buf) >= count {
let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
*self.buf = bytes.slice(count, bytes.len()).to_owned();
bytes.truncate(count);
return Some(bytes);
} else if vec::uniq_len(&const self.buf) > 0 {
let mut bytes = ::core::util::replace(&mut self.buf, ~[]);
} else if vec::uniq_len(&const *self.buf) > 0 {
let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
assert!(count > bytes.len());
match self.try_recv(count - bytes.len()) {
Some(rest) => {
@ -584,11 +586,11 @@ pub mod bytepipes {
}
None => return None
}
} else if vec::uniq_len(&const self.buf) == 0 {
} else if vec::uniq_len(&const *self.buf) == 0 {
match self.port.try_recv() {
Some(buf) => {
assert!(!buf.is_empty());
self.buf = buf;
*self.buf = buf;
return self.try_recv(count);
}
None => return None
@ -609,7 +611,7 @@ pub mod bytepipes {
fn new(p: Port<~[u8]>) -> PipeBytePort {
PipeBytePort {
port: p,
buf: ~[]
buf: @mut ~[]
}
}
}

View File

@ -13,14 +13,14 @@ use core::io;
pub struct BufReader {
buf: ~[u8],
mut pos: uint
pos: @mut uint
}
pub impl BufReader {
pub fn new(v: ~[u8]) -> BufReader {
BufReader {
buf: v,
pos: 0
pos: @mut 0
}
}
@ -29,13 +29,13 @@ pub impl BufReader {
// I can't get the borrowing to work correctly
let bytes_reader = BytesReader {
bytes: ::core::util::id::<&[u8]>(self.buf),
pos: self.pos
pos: *self.pos
};
let res = f(&bytes_reader);
// FIXME #4429: This isn't correct if f fails
self.pos = bytes_reader.pos;
*self.pos = bytes_reader.pos;
return res;
}