Remove low-hanging dependency fruit. (#773) r=nalexander
This commit is contained in:
commit
7d2fe8c625
6 changed files with 29 additions and 26 deletions
|
@ -9,7 +9,6 @@ enum-set = { git = "https://github.com/rnewman/enum-set" }
|
|||
failure = "0.1.1"
|
||||
indexmap = "1"
|
||||
lazy_static = "0.2"
|
||||
num = "0.1"
|
||||
ordered-float = { version = "0.5", features = ["serde"] }
|
||||
uuid = { version = "0.5", features = ["v4", "serde"] }
|
||||
serde = { version = "1.0", features = ["rc"] }
|
||||
|
|
|
@ -14,7 +14,6 @@ indexmap = "1"
|
|||
itertools = "0.7"
|
||||
lazy_static = "0.2"
|
||||
log = "0.4"
|
||||
num = "0.1"
|
||||
ordered-float = "0.5"
|
||||
time = "0.1"
|
||||
petgraph = "0.4.12"
|
||||
|
|
|
@ -76,8 +76,6 @@ use failure::{
|
|||
ResultExt,
|
||||
};
|
||||
|
||||
use num;
|
||||
|
||||
use rusqlite;
|
||||
|
||||
use mentat_core::{
|
||||
|
@ -128,17 +126,10 @@ trait Remove<T> where T: PartialEq {
|
|||
|
||||
impl<T> Remove<T> for Vec<T> where T: PartialEq {
|
||||
/// Remove all occurrences from a vector in-place, by equality.
|
||||
/// Eventually replace with unstable feature: #40062.
|
||||
fn remove_every(&mut self, item: &T) -> usize {
|
||||
let mut removed = 0;
|
||||
let range = num::range_step_inclusive(self.len() as isize - 1, 0, -1);
|
||||
for i in range {
|
||||
if self.get(i as usize).map_or(false, |x| x == item) {
|
||||
self.remove(i as usize);
|
||||
removed += 1;
|
||||
}
|
||||
}
|
||||
removed
|
||||
let initial_len = self.len();
|
||||
self.retain(|v| v != item);
|
||||
initial_len - self.len()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,10 +178,14 @@ impl<K, V> ExtendByAbsorbing for BTreeMap<K, V> where K: Ord, V: Absorb {
|
|||
#[test]
|
||||
fn test_vec_remove_item() {
|
||||
let mut v = vec![1, 2, 3, 4, 5, 4, 3];
|
||||
v.remove_every(&3);
|
||||
let count = v.remove_every(&3);
|
||||
assert_eq!(v, vec![1, 2, 4, 5, 4]);
|
||||
v.remove_every(&4);
|
||||
assert_eq!(count, 2);
|
||||
let count = v.remove_every(&4);
|
||||
assert_eq!(v, vec![1, 2, 5]);
|
||||
assert_eq!(count, 2);
|
||||
let count = v.remove_every(&9);
|
||||
assert_eq!(count, 0);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -15,7 +15,6 @@ extern crate itertools;
|
|||
#[macro_use] extern crate lazy_static;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
extern crate num;
|
||||
extern crate petgraph;
|
||||
extern crate rusqlite;
|
||||
extern crate tabwriter;
|
||||
|
|
|
@ -4,7 +4,6 @@ version = "0.0.1"
|
|||
workspace = ".."
|
||||
|
||||
[dependencies]
|
||||
regex = "0.2"
|
||||
|
||||
[dependencies.mentat_core]
|
||||
path = "../core"
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations under the License.
|
||||
|
||||
extern crate regex;
|
||||
#[macro_use] extern crate mentat_core;
|
||||
extern crate mentat_query;
|
||||
extern crate mentat_query_algebrizer;
|
||||
|
@ -559,15 +558,21 @@ impl QueryFragment for FromClause {
|
|||
}
|
||||
}
|
||||
|
||||
/// `var` is something like `?foo99-people`.
|
||||
/// Trim the `?` and escape the rest. Prepend `i` to distinguish from
|
||||
/// the inline value space `v`.
|
||||
fn format_select_var(var: &str) -> String {
|
||||
use std::iter::once;
|
||||
let without_question = var.split_at(1).1;
|
||||
let replaced_iter = without_question.chars().map(|c|
|
||||
if c.is_ascii_alphanumeric() { c } else { '_' });
|
||||
// Prefix with `i` (Avoiding this copy is probably not worth the trouble but whatever).
|
||||
once('i').chain(replaced_iter).collect()
|
||||
}
|
||||
|
||||
impl SelectQuery {
|
||||
fn push_variable_param(&self, var: &Variable, out: &mut QueryBuilder) -> BuildQueryResult {
|
||||
// `var` is something like `?foo99-people`.
|
||||
// Trim the `?` and escape the rest. Prepend `i` to distinguish from
|
||||
// the inline value space `v`.
|
||||
let re = regex::Regex::new("[^a-zA-Z_0-9]").unwrap();
|
||||
let without_question = var.as_str().split_at(1).1;
|
||||
let replaced = re.replace_all(without_question, "_");
|
||||
let bind_param = format!("i{}", replaced); // We _could_ avoid this copying.
|
||||
let bind_param = format_select_var(var.as_str());
|
||||
out.push_bind_param(bind_param.as_str())
|
||||
}
|
||||
}
|
||||
|
@ -817,4 +822,11 @@ mod tests {
|
|||
assert!(args.is_empty());
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_select_var() {
|
||||
assert_eq!(format_select_var("?foo99-people"), "ifoo99_people");
|
||||
assert_eq!(format_select_var("?FOO99-pëople.123"), "iFOO99_p_ople_123");
|
||||
assert_eq!(format_select_var("?foo①bar越"), "ifoo_bar_");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue