From 903f674257d075d744f643edc8269132fa928d7e Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 28 Jun 2019 00:30:12 -0700 Subject: [PATCH] Assume Postgres isn't lying (use UTF-8 unchecked) --- sqlx-postgres-protocol/src/decode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-postgres-protocol/src/decode.rs b/sqlx-postgres-protocol/src/decode.rs index c1a00ffbc..865fa97af 100644 --- a/sqlx-postgres-protocol/src/decode.rs +++ b/sqlx-postgres-protocol/src/decode.rs @@ -12,7 +12,7 @@ pub trait Decode { pub(crate) fn get_str(src: &[u8]) -> io::Result<&str> { let end = memchr(b'\0', &src).ok_or(io::ErrorKind::UnexpectedEof)?; let buf = &src[..end]; - let s = str::from_utf8(buf).map_err(|_| io::ErrorKind::InvalidData)?; + let s = unsafe { str::from_utf8_unchecked(buf) }; Ok(s) }