From bc61634dbafdb679aac7b079afd195c87280fdfa Mon Sep 17 00:00:00 2001 From: Knight Date: Sat, 20 Aug 2016 02:25:55 +0800 Subject: [PATCH] tr: use HashMap in stdlib instead of vec_map --- src/tr/Cargo.toml | 7 ++++--- src/tr/tr.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/tr/Cargo.toml b/src/tr/Cargo.toml index 81291ea18..b089c8cc6 100644 --- a/src/tr/Cargo.toml +++ b/src/tr/Cargo.toml @@ -9,10 +9,11 @@ path = "tr.rs" [dependencies] getopts = "*" -libc = "*" bit-set = "*" -vec_map = "0.6.0" -uucore = { path="../uucore" } + +[dependencies.uucore] +path = "../uucore" +default-features = false [[bin]] name = "tr" diff --git a/src/tr/tr.rs b/src/tr/tr.rs index fc6fae3bb..e67eed0ca 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -13,7 +13,6 @@ extern crate bit_set; extern crate getopts; -extern crate vec_map; #[macro_use] extern crate uucore; @@ -21,7 +20,7 @@ extern crate uucore; use bit_set::BitSet; use getopts::Options; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; -use vec_map::VecMap; +use std::collections::HashMap; use expand::ExpandSet; @@ -62,7 +61,8 @@ fn delete(set: ExpandSet, complement: bool) { } fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) { - let mut map = VecMap::new(); + //let mut map = VecMap::new(); + let mut map = HashMap::new(); let stdout = stdout(); let mut buf = String::with_capacity(BUFFER_LEN + 4); @@ -82,10 +82,10 @@ fn tr<'a>(set1: ExpandSet<'a>, mut set2: ExpandSet<'a>) { { let mut chars = buf.chars(); - while let Some(char) = chars.next() { - let trc = match map.get(char as usize) { + while let Some(ch) = chars.next() { + let trc = match map.get(&(ch as usize)) { Some(t) => *t, - None => char, + None => ch, }; safe_unwrap!(writer.write_all(format!("{}", trc).as_ref())); }