Skip to content

Commit 180c13d

Browse files
committed
Clean up string creation
1 parent ecea567 commit 180c13d

3 files changed

Lines changed: 11 additions & 16 deletions

File tree

src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ use std::io::net::ip::{Port, SocketAddr};
9090
use std::io::net::tcp::TcpStream;
9191
use std::io::net::unix::UnixStream;
9292
use std::mem;
93-
use std::str;
9493
use std::task;
9594
use std::fmt;
9695

@@ -809,11 +808,11 @@ impl InnerPostgresConnection {
809808
loop {
810809
match try_pg!(self.read_message()) {
811810
ReadyForQuery { .. } => break,
812-
DataRow { row } =>
813-
// FIXME
814-
result.push(row.move_iter().map(|opt|
815-
opt.map(|b| str::from_utf8(b.as_slice()).unwrap().to_owned()))
816-
.collect()),
811+
DataRow { row } => {
812+
result.push(row.move_iter().map(|opt| {
813+
opt.map(|b| StrBuf::from_utf8(b).unwrap().into_owned())
814+
}).collect());
815+
}
817816
ErrorResponse { fields } => {
818817
try!(self.wait_for_ready());
819818
return Err(PgDbError(PostgresDbError::new(fields)));

src/message.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::str;
21
use std::io::{IoResult, MemWriter, MemReader};
32
use std::mem;
43

@@ -245,8 +244,7 @@ impl<R: Buffer> ReadCStr for R {
245244
fn read_cstr(&mut self) -> IoResult<~str> {
246245
let mut buf = try!(self.read_until(0));
247246
buf.pop();
248-
// FIXME
249-
Ok(str::from_utf8(buf.as_slice()).unwrap().to_owned())
247+
Ok(StrBuf::from_utf8(buf).unwrap().into_owned())
250248
}
251249
}
252250

src/types/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use serialize::json;
77
use serialize::json::Json;
88
use std::io::{MemWriter, BufReader};
99
use std::io::util::LimitReader;
10-
use std::str;
1110
use time::Timespec;
1211

1312
use error::{PostgresError, PgWrongType, PgStreamError, PgWasNull};
@@ -267,8 +266,7 @@ impl RawFromSql for Vec<u8> {
267266
impl RawFromSql for ~str {
268267
fn raw_from_sql<R: Reader>(raw: &mut R)
269268
-> Result<~str, PostgresError> {
270-
// FIXME
271-
Ok(str::from_utf8(try_pg!(raw.read_to_end()).as_slice()).unwrap().to_owned())
269+
Ok(StrBuf::from_utf8(try_pg!(raw.read_to_end())).unwrap().into_owned())
272270
}
273271
}
274272

@@ -483,15 +481,15 @@ impl FromSql for Option<HashMap<~str, Option<~str>>> {
483481

484482
for _ in range(0, count) {
485483
let key_len = try_pg!(rdr.read_be_i32());
486-
let key = str::from_utf8(try_pg!(rdr.read_exact(key_len as uint)).as_slice())
487-
.unwrap().to_owned();
484+
let key = try_pg!(rdr.read_exact(key_len as uint));
485+
let key = StrBuf::from_utf8(key).unwrap().into_owned();
488486

489487
let val_len = try_pg!(rdr.read_be_i32());
490488
let val = if val_len < 0 {
491489
None
492490
} else {
493-
Some(str::from_utf8(try_pg!(rdr.read_exact(val_len as uint)).as_slice())
494-
.unwrap().to_owned())
491+
let val = try_pg!(rdr.read_exact(val_len as uint));
492+
Some(StrBuf::from_utf8(val).unwrap().into_owned())
495493
};
496494

497495
map.insert(key, val);

0 commit comments

Comments
 (0)