From 60d7a1c1738b23971ba07976d1bbfd89200d0c29 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Mon, 10 May 2021 17:42:06 +0530 Subject: [PATCH] Optimize will_cursor_give_char check --- server/src/protocol/parserv2.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/src/protocol/parserv2.rs b/server/src/protocol/parserv2.rs index 82eee499..6eb198df 100644 --- a/server/src/protocol/parserv2.rs +++ b/server/src/protocol/parserv2.rs @@ -24,7 +24,11 @@ * */ +use std::hint::unreachable_unchecked; + /// The header magic (a '\r' or CR) +/// +/// This demarcates distinct query packets; all queries begin with this byte const START_HEADER_MAGIC: u8 = 0x0D; #[derive(Debug)] @@ -239,7 +243,14 @@ impl<'a> Parser<'a> { // The below line defaults to false if no item is there in the buffer // or it checks if the next time is a \r char; if it is, then it is the beginning // of the next query - if self.will_cursor_give_char(b'\r', true)? { + if self + .will_cursor_give_char(b'\r', true) + .unwrap_or_else(|_| unsafe { + // This will never be the case because we'll always get a result and no error value + // as we've passed true which will yield Ok(true) even if there is no byte ahead + unreachable_unchecked() + }) + { Ok((Query::SimpleQuery(single_group), self.cursor)) } else { // the next item isn't the beginning of a query but something else?