Removing some mutable fields in libstd
This commit is contained in:
parent
5641777318
commit
3136fba5ae
7 changed files with 91 additions and 92 deletions
|
@ -259,7 +259,7 @@ struct RWARCInner<T> { lock: RWlock, failed: bool, data: T }
|
|||
*/
|
||||
struct RWARC<T> {
|
||||
x: SharedMutableState<RWARCInner<T>>,
|
||||
mut cant_nest: ()
|
||||
cant_nest: ()
|
||||
}
|
||||
|
||||
/// Create a reader/writer ARC with the supplied data.
|
||||
|
|
|
@ -360,9 +360,9 @@ pub fn to_pretty_str(json: &Json) -> ~str {
|
|||
|
||||
pub struct Parser {
|
||||
priv rdr: @io::Reader,
|
||||
priv mut ch: char,
|
||||
priv mut line: uint,
|
||||
priv mut col: uint,
|
||||
priv ch: char,
|
||||
priv line: uint,
|
||||
priv col: uint,
|
||||
}
|
||||
|
||||
/// Decode a json value from an io::reader
|
||||
|
@ -376,7 +376,7 @@ pub fn Parser(rdr: @io::Reader) -> Parser {
|
|||
}
|
||||
|
||||
pub impl Parser {
|
||||
fn parse(&self) -> Result<Json, Error> {
|
||||
fn parse(&mut self) -> Result<Json, Error> {
|
||||
match self.parse_value() {
|
||||
Ok(value) => {
|
||||
// Skip trailing whitespaces.
|
||||
|
@ -396,7 +396,7 @@ pub impl Parser {
|
|||
priv impl Parser {
|
||||
fn eof(&self) -> bool { self.ch == -1 as char }
|
||||
|
||||
fn bump(&self) {
|
||||
fn bump(&mut self) {
|
||||
self.ch = self.rdr.read_char();
|
||||
|
||||
if self.ch == '\n' {
|
||||
|
@ -407,7 +407,7 @@ priv impl Parser {
|
|||
}
|
||||
}
|
||||
|
||||
fn next_char(&self) -> char {
|
||||
fn next_char(&mut self) -> char {
|
||||
self.bump();
|
||||
self.ch
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ priv impl Parser {
|
|||
Err(Error { line: self.line, col: self.col, msg: @msg })
|
||||
}
|
||||
|
||||
fn parse_value(&self) -> Result<Json, Error> {
|
||||
fn parse_value(&mut self) -> Result<Json, Error> {
|
||||
self.parse_whitespace();
|
||||
|
||||
if self.eof() { return self.error(~"EOF while parsing value"); }
|
||||
|
@ -437,11 +437,11 @@ priv impl Parser {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_whitespace(&self) {
|
||||
fn parse_whitespace(&mut self) {
|
||||
while char::is_whitespace(self.ch) { self.bump(); }
|
||||
}
|
||||
|
||||
fn parse_ident(&self, ident: &str, value: Json) -> Result<Json, Error> {
|
||||
fn parse_ident(&mut self, ident: &str, value: Json) -> Result<Json, Error> {
|
||||
if str::all(ident, |c| c == self.next_char()) {
|
||||
self.bump();
|
||||
Ok(value)
|
||||
|
@ -450,7 +450,7 @@ priv impl Parser {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_number(&self) -> Result<Json, Error> {
|
||||
fn parse_number(&mut self) -> Result<Json, Error> {
|
||||
let mut neg = 1f;
|
||||
|
||||
if self.ch == '-' {
|
||||
|
@ -480,7 +480,7 @@ priv impl Parser {
|
|||
Ok(Number(neg * res))
|
||||
}
|
||||
|
||||
fn parse_integer(&self) -> Result<float, Error> {
|
||||
fn parse_integer(&mut self) -> Result<float, Error> {
|
||||
let mut res = 0f;
|
||||
|
||||
match self.ch {
|
||||
|
@ -512,7 +512,7 @@ priv impl Parser {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
fn parse_decimal(&self, res: float) -> Result<float, Error> {
|
||||
fn parse_decimal(&mut self, res: float) -> Result<float, Error> {
|
||||
self.bump();
|
||||
|
||||
// Make sure a digit follows the decimal place.
|
||||
|
@ -538,10 +538,9 @@ priv impl Parser {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
fn parse_exponent(&self, res: float) -> Result<float, Error> {
|
||||
fn parse_exponent(&mut self, mut res: float) -> Result<float, Error> {
|
||||
self.bump();
|
||||
|
||||
let mut res = res;
|
||||
let mut exp = 0u;
|
||||
let mut neg_exp = false;
|
||||
|
||||
|
@ -579,7 +578,7 @@ priv impl Parser {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
fn parse_str(&self) -> Result<~str, Error> {
|
||||
fn parse_str(&mut self) -> Result<~str, Error> {
|
||||
let mut escape = false;
|
||||
let mut res = ~"";
|
||||
|
||||
|
@ -643,7 +642,7 @@ priv impl Parser {
|
|||
self.error(~"EOF while parsing string")
|
||||
}
|
||||
|
||||
fn parse_list(&self) -> Result<Json, Error> {
|
||||
fn parse_list(&mut self) -> Result<Json, Error> {
|
||||
self.bump();
|
||||
self.parse_whitespace();
|
||||
|
||||
|
@ -673,7 +672,7 @@ priv impl Parser {
|
|||
};
|
||||
}
|
||||
|
||||
fn parse_object(&self) -> Result<Json, Error> {
|
||||
fn parse_object(&mut self) -> Result<Json, Error> {
|
||||
self.bump();
|
||||
self.parse_whitespace();
|
||||
|
||||
|
@ -726,7 +725,8 @@ priv impl Parser {
|
|||
|
||||
/// Decodes a json value from an @io::Reader
|
||||
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
|
||||
Parser(rdr).parse()
|
||||
let mut parser = Parser(rdr);
|
||||
parser.parse()
|
||||
}
|
||||
|
||||
/// Decodes a json value from a string
|
||||
|
|
|
@ -239,7 +239,6 @@ mod test {
|
|||
|
||||
mod arith {
|
||||
use super::*;
|
||||
use super::super::*;
|
||||
use core::num::Zero;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -455,7 +455,7 @@ pub mod iterator {
|
|||
node::Content(x) => return node::leaf_iterator::start(x)
|
||||
}
|
||||
}
|
||||
pub fn next(it: &node::leaf_iterator::T) -> Option<node::Leaf> {
|
||||
pub fn next(it: &mut node::leaf_iterator::T) -> Option<node::Leaf> {
|
||||
return node::leaf_iterator::next(it);
|
||||
}
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ pub mod iterator {
|
|||
node::Content(x) => return node::char_iterator::start(x)
|
||||
}
|
||||
}
|
||||
pub fn next(it: &node::char_iterator::T) -> Option<char> {
|
||||
pub fn next(it: &mut node::char_iterator::T) -> Option<char> {
|
||||
return node::char_iterator::next(it)
|
||||
}
|
||||
}
|
||||
|
@ -832,9 +832,9 @@ pub mod node {
|
|||
unsafe {
|
||||
let mut buf = vec::from_elem(byte_len(node), 0);
|
||||
let mut offset = 0u;//Current position in the buffer
|
||||
let it = leaf_iterator::start(node);
|
||||
let mut it = leaf_iterator::start(node);
|
||||
loop {
|
||||
match (leaf_iterator::next(&it)) {
|
||||
match leaf_iterator::next(&mut it) {
|
||||
option::None => break,
|
||||
option::Some(x) => {
|
||||
//FIXME (#2744): Replace with memcpy or something similar
|
||||
|
@ -896,9 +896,9 @@ pub mod node {
|
|||
if height(node) < hint_max_node_height { return option::None; }
|
||||
//1. Gather all leaves as a forest
|
||||
let mut forest = ~[];
|
||||
let it = leaf_iterator::start(node);
|
||||
let mut it = leaf_iterator::start(node);
|
||||
loop {
|
||||
match (leaf_iterator::next(&it)) {
|
||||
match leaf_iterator::next(&mut it) {
|
||||
option::None => break,
|
||||
option::Some(x) => forest.push(@Leaf(x))
|
||||
}
|
||||
|
@ -1058,11 +1058,12 @@ pub mod node {
|
|||
}
|
||||
|
||||
pub fn cmp(a: @Node, b: @Node) -> int {
|
||||
let ita = char_iterator::start(a);
|
||||
let itb = char_iterator::start(b);
|
||||
let mut ita = char_iterator::start(a);
|
||||
let mut itb = char_iterator::start(b);
|
||||
let mut result = 0;
|
||||
while result == 0 {
|
||||
match ((char_iterator::next(&ita), char_iterator::next(&itb))) {
|
||||
match (char_iterator::next(&mut ita), char_iterator::next(&mut itb))
|
||||
{
|
||||
(option::None, option::None) => break,
|
||||
(option::Some(chara), option::Some(charb)) => {
|
||||
result = char::cmp(chara, charb);
|
||||
|
@ -1131,9 +1132,7 @@ pub mod node {
|
|||
* proportional to the height of the rope + the (bounded)
|
||||
* length of the largest leaf.
|
||||
*/
|
||||
pub fn char_at(node: @Node, pos: uint) -> char {
|
||||
let mut node = node;
|
||||
let mut pos = pos;
|
||||
pub fn char_at(mut node: @Node, mut pos: uint) -> char {
|
||||
loop {
|
||||
match *node {
|
||||
Leaf(x) => return str::char_at(*x.content, pos),
|
||||
|
@ -1154,8 +1153,8 @@ pub mod node {
|
|||
use core::vec;
|
||||
|
||||
pub struct T {
|
||||
mut stack: ~[@Node],
|
||||
mut stackpos: int,
|
||||
stack: ~[@Node],
|
||||
stackpos: int,
|
||||
}
|
||||
|
||||
pub fn empty() -> T {
|
||||
|
@ -1171,7 +1170,7 @@ pub mod node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn next(it: &T) -> Option<Leaf> {
|
||||
pub fn next(it: &mut T) -> Option<Leaf> {
|
||||
if it.stackpos < 0 { return option::None; }
|
||||
loop {
|
||||
let current = it.stack[it.stackpos];
|
||||
|
@ -1199,8 +1198,8 @@ pub mod node {
|
|||
|
||||
pub struct T {
|
||||
leaf_iterator: leaf_iterator::T,
|
||||
mut leaf: Option<Leaf>,
|
||||
mut leaf_byte_pos: uint,
|
||||
leaf: Option<Leaf>,
|
||||
leaf_byte_pos: uint,
|
||||
}
|
||||
|
||||
pub fn start(node: @Node) -> T {
|
||||
|
@ -1219,13 +1218,13 @@ pub mod node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn next(it: &T) -> Option<char> {
|
||||
pub fn next(it: &mut T) -> Option<char> {
|
||||
loop {
|
||||
match (get_current_or_next_leaf(it)) {
|
||||
match get_current_or_next_leaf(it) {
|
||||
option::None => return option::None,
|
||||
option::Some(_) => {
|
||||
let next_char = get_next_char_in_leaf(it);
|
||||
match (next_char) {
|
||||
match next_char {
|
||||
option::None => loop,
|
||||
option::Some(_) => return next_char
|
||||
}
|
||||
|
@ -1234,16 +1233,16 @@ pub mod node {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn get_current_or_next_leaf(it: &T) -> Option<Leaf> {
|
||||
match ((*it).leaf) {
|
||||
option::Some(_) => return (*it).leaf,
|
||||
pub fn get_current_or_next_leaf(it: &mut T) -> Option<Leaf> {
|
||||
match it.leaf {
|
||||
option::Some(_) => return it.leaf,
|
||||
option::None => {
|
||||
let next = leaf_iterator::next(&((*it).leaf_iterator));
|
||||
match (next) {
|
||||
let next = leaf_iterator::next(&mut it.leaf_iterator);
|
||||
match next {
|
||||
option::None => return option::None,
|
||||
option::Some(_) => {
|
||||
(*it).leaf = next;
|
||||
(*it).leaf_byte_pos = 0u;
|
||||
it.leaf = next;
|
||||
it.leaf_byte_pos = 0u;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
@ -1251,13 +1250,13 @@ pub mod node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_next_char_in_leaf(it: &T) -> Option<char> {
|
||||
match copy (*it).leaf {
|
||||
pub fn get_next_char_in_leaf(it: &mut T) -> Option<char> {
|
||||
match copy it.leaf {
|
||||
option::None => return option::None,
|
||||
option::Some(aleaf) => {
|
||||
if (*it).leaf_byte_pos >= aleaf.byte_len {
|
||||
if it.leaf_byte_pos >= aleaf.byte_len {
|
||||
//We are actually past the end of the leaf
|
||||
(*it).leaf = option::None;
|
||||
it.leaf = option::None;
|
||||
return option::None
|
||||
} else {
|
||||
let range =
|
||||
|
@ -1343,10 +1342,10 @@ mod tests {
|
|||
|
||||
let mut string_iter = 0u;
|
||||
let string_len = str::len(*sample);
|
||||
let rope_iter = iterator::char::start(r);
|
||||
let mut rope_iter = iterator::char::start(r);
|
||||
let mut equal = true;
|
||||
while equal {
|
||||
match (node::char_iterator::next(&rope_iter)) {
|
||||
match (node::char_iterator::next(&mut rope_iter)) {
|
||||
option::None => {
|
||||
if string_iter < string_len {
|
||||
equal = false;
|
||||
|
@ -1376,9 +1375,9 @@ mod tests {
|
|||
let r = of_str(sample);
|
||||
|
||||
let mut len = 0u;
|
||||
let it = iterator::char::start(r);
|
||||
let mut it = iterator::char::start(r);
|
||||
loop {
|
||||
match (node::char_iterator::next(&it)) {
|
||||
match (node::char_iterator::next(&mut it)) {
|
||||
option::None => break,
|
||||
option::Some(_) => len += 1u
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ fn broadcast_waitqueue(q: &Waitqueue) -> uint {
|
|||
// The building-block used to make semaphores, mutexes, and rwlocks.
|
||||
#[doc(hidden)]
|
||||
struct SemInner<Q> {
|
||||
mut count: int,
|
||||
count: int,
|
||||
waiters: Waitqueue,
|
||||
// Can be either unit or another waitqueue. Some sems shouldn't come with
|
||||
// a condition variable attached, others should.
|
||||
|
@ -729,7 +729,6 @@ mod tests {
|
|||
|
||||
use core::cast;
|
||||
use core::cell::Cell;
|
||||
use core::option;
|
||||
use core::ptr;
|
||||
use core::result;
|
||||
use core::task;
|
||||
|
|
|
@ -26,8 +26,7 @@ enum Msg<T> {
|
|||
|
||||
pub struct TaskPool<T> {
|
||||
channels: ~[Chan<Msg<T>>],
|
||||
mut next_index: uint,
|
||||
|
||||
next_index: uint,
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
|
@ -84,7 +83,7 @@ pub impl<T> TaskPool<T> {
|
|||
|
||||
/// Executes the function `f` on a task in the pool. The function
|
||||
/// receives a reference to the local data returned by the `init_fn`.
|
||||
fn execute(&self, f: ~fn(&T)) {
|
||||
fn execute(&mut self, f: ~fn(&T)) {
|
||||
self.channels[self.next_index].send(Execute(f));
|
||||
self.next_index += 1;
|
||||
if self.next_index == self.channels.len() { self.next_index = 0; }
|
||||
|
@ -97,7 +96,7 @@ fn test_task_pool() {
|
|||
let g: ~fn(uint) -> uint = |i| i;
|
||||
g
|
||||
};
|
||||
let pool = TaskPool::new(4, Some(SingleThreaded), f);
|
||||
let mut pool = TaskPool::new(4, Some(SingleThreaded), f);
|
||||
for 8.times {
|
||||
pool.execute(|i| io::println(fmt!("Hello from thread %u!", *i)));
|
||||
}
|
||||
|
|
|
@ -201,19 +201,19 @@ struct ConsoleTestState {
|
|||
out: @io::Writer,
|
||||
log_out: Option<@io::Writer>,
|
||||
use_color: bool,
|
||||
mut total: uint,
|
||||
mut passed: uint,
|
||||
mut failed: uint,
|
||||
mut ignored: uint,
|
||||
mut benchmarked: uint,
|
||||
mut failures: ~[TestDesc]
|
||||
total: uint,
|
||||
passed: uint,
|
||||
failed: uint,
|
||||
ignored: uint,
|
||||
benchmarked: uint,
|
||||
failures: ~[TestDesc]
|
||||
}
|
||||
|
||||
// A simple console test runner
|
||||
pub fn run_tests_console(opts: &TestOpts,
|
||||
tests: ~[TestDescAndFn]) -> bool {
|
||||
|
||||
fn callback(event: &TestEvent, st: @ConsoleTestState) {
|
||||
fn callback(event: &TestEvent, st: &mut ConsoleTestState) {
|
||||
debug!("callback(event=%?)", event);
|
||||
match *event {
|
||||
TeFiltered(ref filtered_tests) => {
|
||||
|
@ -268,16 +268,16 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
None => None
|
||||
};
|
||||
|
||||
let st = @ConsoleTestState {
|
||||
let st = @mut ConsoleTestState {
|
||||
out: io::stdout(),
|
||||
log_out: log_out,
|
||||
use_color: use_color(),
|
||||
mut total: 0u,
|
||||
mut passed: 0u,
|
||||
mut failed: 0u,
|
||||
mut ignored: 0u,
|
||||
mut benchmarked: 0u,
|
||||
mut failures: ~[]
|
||||
total: 0u,
|
||||
passed: 0u,
|
||||
failed: 0u,
|
||||
ignored: 0u,
|
||||
benchmarked: 0u,
|
||||
failures: ~[]
|
||||
};
|
||||
|
||||
run_tests(opts, tests, |x| callback(&x, st));
|
||||
|
@ -290,6 +290,8 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
print_failures(st);
|
||||
}
|
||||
|
||||
{
|
||||
let st: &mut ConsoleTestState = st;
|
||||
st.out.write_str(fmt!("\nresult: "));
|
||||
if success {
|
||||
// There's no parallelism at this point so it's safe to use color
|
||||
|
@ -299,6 +301,7 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
}
|
||||
st.out.write_str(fmt!(". %u passed; %u failed; %u ignored\n\n",
|
||||
st.passed, st.failed, st.ignored));
|
||||
}
|
||||
|
||||
return success;
|
||||
|
||||
|
@ -356,7 +359,7 @@ pub fn run_tests_console(opts: &TestOpts,
|
|||
}
|
||||
}
|
||||
|
||||
fn print_failures(st: @ConsoleTestState) {
|
||||
fn print_failures(st: &ConsoleTestState) {
|
||||
st.out.write_line(~"\nfailures:");
|
||||
let mut failures = ~[];
|
||||
for uint::range(0, vec::uniq_len(&const st.failures)) |i| {
|
||||
|
@ -390,12 +393,12 @@ fn should_sort_failures_before_printing_them() {
|
|||
out: wr,
|
||||
log_out: option::None,
|
||||
use_color: false,
|
||||
mut total: 0u,
|
||||
mut passed: 0u,
|
||||
mut failed: 0u,
|
||||
mut ignored: 0u,
|
||||
mut benchmarked: 0u,
|
||||
mut failures: ~[test_b, test_a]
|
||||
total: 0u,
|
||||
passed: 0u,
|
||||
failed: 0u,
|
||||
ignored: 0u,
|
||||
benchmarked: 0u,
|
||||
failures: ~[test_b, test_a]
|
||||
};
|
||||
|
||||
print_failures(st);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue