From fe2a6660eab170683bd41607eeee600595777dda Mon Sep 17 00:00:00 2001 From: Anthony Miyaguchi Date: Tue, 20 Dec 2016 22:43:04 -0800 Subject: [PATCH 1/2] Replace `into_cow` with equivalent Cow:: constructor --- src/queryplan/execute/groupbuckets.rs | 11 +++++------ src/queryplan/mod.rs | 6 +++--- src/tempdb/mod.rs | 6 +++--- src/types/variant.rs | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/queryplan/execute/groupbuckets.rs b/src/queryplan/execute/groupbuckets.rs index 2b4f2a9..6c789be 100644 --- a/src/queryplan/execute/groupbuckets.rs +++ b/src/queryplan/execute/groupbuckets.rs @@ -62,9 +62,10 @@ impl Group for GroupBucket(&'b self) -> Option> { - use std::borrow::IntoCow; - - self.rows.iter().nth(0).map(|r| r.into_cow()) + self.rows.iter().nth(0).map(|row| { + let row_ref: &[ColumnValue] = &row; + Cow::Borrowed(row_ref) + }) } fn count(&self) -> u64 { @@ -73,10 +74,8 @@ impl Group for GroupBucket(&'a self) -> Box> + 'a> { Box::new(self.rows.iter().map(|row| { - use std::borrow::IntoCow; - let row_ref: &[ColumnValue] = &row; - row_ref.into_cow() + Cow::Borrowed(row_ref) })) } } diff --git a/src/queryplan/mod.rs b/src/queryplan/mod.rs index 996b625..2a580bb 100644 --- a/src/queryplan/mod.rs +++ b/src/queryplan/mod.rs @@ -663,7 +663,7 @@ where DB: 'a, ::Table: 'a groups_info: &mut GroupsInfo) -> Result, QueryPlanCompileError> { - use std::borrow::IntoCow; + use std::borrow::Cow; match ast { ast::Expression::Ident(s) => { @@ -718,13 +718,13 @@ where DB: 'a, ::Table: 'a }) }, ast::Expression::StringLiteral(s) => { - match DB::ColumnValue::from_string_literal(s.into_cow()) { + match DB::ColumnValue::from_string_literal(Cow::Borrowed(&s)) { Ok(value) => Ok(SExpression::Value(value)), Err(s) => Err(QueryPlanCompileError::BadStringLiteral(s.into_owned())) } }, ast::Expression::Number(s) => { - match DB::ColumnValue::from_number_literal(s.into_cow()) { + match DB::ColumnValue::from_number_literal(Cow::Borrowed(&s)) { Ok(value) => Ok(SExpression::Value(value)), Err(s) => Err(QueryPlanCompileError::BadNumberLiteral(s.into_owned())) } diff --git a/src/tempdb/mod.rs b/src/tempdb/mod.rs index 3964078..415e8d5 100644 --- a/src/tempdb/mod.rs +++ b/src/tempdb/mod.rs @@ -63,7 +63,7 @@ impl<'a> Group for ScanGroup<'a> { Box::new(table.rowid_index.iter().map(move |key_v| { use byteutils; - use std::borrow::IntoCow; + use std::borrow::Cow; let raw_key: &[u8] = &key_v; trace!("KEY: {:?}", raw_key); @@ -108,13 +108,13 @@ impl<'a> Group for ScanGroup<'a> { let bytes = &raw_key[key_offset..key_offset + size]; trace!("from bytes: {:?}, {:?}", column.dbtype, bytes); - let value = ColumnValueOps::from_bytes(column.dbtype, bytes.into_cow()).unwrap(); + let value = ColumnValueOps::from_bytes(column.dbtype, Cow::Borrowed(bytes)).unwrap(); key_offset += size; value } }).collect(); - v.into_cow() + Cow::Owned(v) })) } } diff --git a/src/types/variant.rs b/src/types/variant.rs index c8e82f6..6b76c72 100644 --- a/src/types/variant.rs +++ b/src/types/variant.rs @@ -2,7 +2,7 @@ use byteutils; use columnvalueops::ColumnValueOps; use types::DbType; use types::F64NoNaN; -use std::borrow::{Cow, IntoCow}; +use std::borrow::Cow; use std::fmt; #[derive(Clone, Hash, Eq, PartialEq, Ord, PartialOrd)] @@ -215,7 +215,7 @@ impl ColumnValueOps for Variant { (Variant::Bytes(bytes), v) => { // every variant can be converted from their byte representation let r: &[u8] = &bytes; - match ColumnValueOps::from_bytes(v, r.into_cow()) { + match ColumnValueOps::from_bytes(v, Cow::Borrowed(r)) { Ok(s) => Some(s), Err(()) => None } From dad4ff5a2e159d2b942b870c3ab17fcbe903e15f Mon Sep 17 00:00:00 2001 From: Anthony Miyaguchi Date: Tue, 20 Dec 2016 22:59:53 -0800 Subject: [PATCH 2/2] Replace Duration::span with Instant::now().elapsed --- cli/src/main.rs | 12 ++++-------- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index 28b2b1b..71dacaa 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,3 @@ -#![feature(duration_span)] - #[macro_use] extern crate log; @@ -9,7 +7,7 @@ extern crate linenoise; extern crate llamadb; use std::io::Write; -use std::time::Duration; +use std::time::Instant; mod prettyselect; use prettyselect::pretty_select; @@ -82,12 +80,10 @@ fn execute_statement(out: &mut Write, db: &mut llamadb::tempdb::TempDb, statemen { use llamadb::tempdb::ExecuteStatementResponse; - let mut execute_result = None; + let now = Instant::now(); + let execute_result = Some(db.execute_statement(statement)); + let duration = now.elapsed(); - let duration = Duration::span(|| { - execute_result = Some(db.execute_statement(statement)); - }); - let seconds = duration.as_secs() as f32 + (duration.subsec_nanos() as f32 * 1.0e-9); let duration_string = format!("{:.3}s", seconds); diff --git a/src/lib.rs b/src/lib.rs index fe5c770..f483a4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(into_cow, associated_type_defaults)] +#![feature(associated_type_defaults)] #[macro_use] extern crate log;