From 55c89a917ad616c0d7d93da0496f371aa3bb0815 Mon Sep 17 00:00:00 2001 From: shnatsel Date: Sun, 26 May 2019 15:43:31 +0200 Subject: [PATCH] Drop unsafe code from currently unsound function prefix() This incurs at about 1% performance penalty. It can probably be avoided by using slice::windows() in flush() instead of indexing. --- src/lz77/default.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lz77/default.rs b/src/lz77/default.rs index f11aae0..d00dd94 100644 --- a/src/lz77/default.rs +++ b/src/lz77/default.rs @@ -109,14 +109,9 @@ impl Lz77Encode for DefaultLz77Encoder { } #[inline] -fn prefix(buf: &[u8]) -> [u8; 3] { - unsafe { - [ - *buf.get_unchecked(0), - *buf.get_unchecked(1), - *buf.get_unchecked(2), - ] - } +fn prefix(input_buf: &[u8]) -> [u8; 3] { + let buf: &[u8] = &input_buf[..3]; // perform bounds check once + [buf[0], buf[1], buf[2]] } #[inline]