Skip to content

Commit f2083a0

Browse files
committed
Cleanup
1 parent 310a488 commit f2083a0

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/lib.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extern crate log;
7979
extern crate phf;
8080
extern crate postgres_protocol;
8181

82-
use fallible_iterator::FallibleIterator;
82+
use fallible_iterator::{FallibleIterator, FromFallibleIterator};
8383
use std::cell::{Cell, RefCell};
8484
use std::collections::{VecDeque, HashMap};
8585
use std::fmt;
@@ -504,14 +504,7 @@ impl InnerConnection {
504504
more_rows = true;
505505
break;
506506
}
507-
backend::Message::DataRow(body) => {
508-
let mut row = RowData::new();
509-
let mut it = body.values();
510-
while let Some(value) = try!(it.next()) {
511-
row.push(value);
512-
}
513-
consumer(row);
514-
}
507+
backend::Message::DataRow(body) => consumer(try!(body.values().collect())),
515508
backend::Message::ErrorResponse(body) => {
516509
try!(self.wait_for_ready());
517510
return DbError::new(&mut body.fields());
@@ -1338,26 +1331,32 @@ struct RowData {
13381331
indices: Vec<Option<Range<usize>>>,
13391332
}
13401333

1341-
impl RowData {
1342-
fn new() -> RowData {
1343-
RowData {
1334+
impl<'a> FromFallibleIterator<Option<&'a [u8]>> for RowData {
1335+
fn from_fallible_iterator<I>(mut it: I) -> result::Result<Self, I::Error>
1336+
where I: FallibleIterator<Item = Option<&'a [u8]>>
1337+
{
1338+
let mut row = RowData {
13441339
buf: vec![],
1345-
indices: vec![],
1340+
indices: Vec::with_capacity(it.size_hint().0),
1341+
};
1342+
1343+
while let Some(cell) = try!(it.next()) {
1344+
let index = match cell {
1345+
Some(cell) => {
1346+
let base = row.buf.len();
1347+
row.buf.extend_from_slice(cell);
1348+
Some(base..row.buf.len())
1349+
}
1350+
None => None,
1351+
};
1352+
row.indices.push(index);
13461353
}
1347-
}
13481354

1349-
fn push(&mut self, cell: Option<&[u8]>) {
1350-
let index = match cell {
1351-
Some(cell) => {
1352-
let base = self.buf.len();
1353-
self.buf.extend_from_slice(cell);
1354-
Some(base..self.buf.len())
1355-
}
1356-
None => None,
1357-
};
1358-
self.indices.push(index);
1355+
Ok(row)
13591356
}
1357+
}
13601358

1359+
impl RowData {
13611360
fn len(&self) -> usize {
13621361
self.indices.len()
13631362
}

0 commit comments

Comments
 (0)