Skip to content

Commit 0184b19

Browse files
committed
Simplify read_scriptbool
Simplify `read_scriptbool` by doing: - Use `split_last` to get at the last element - Mask the last byte against ^0x80 instead of using two equality statements
1 parent 0d439c7 commit 0184b19

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/blockdata/script.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,10 @@ pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
239239
/// else as true", except that the overflow rules don't apply.
240240
#[inline]
241241
pub fn read_scriptbool(v: &[u8]) -> bool {
242-
let last = match v.last() {
243-
Some(last) => *last,
244-
None => return false,
245-
};
246-
247-
!((last == 0x00 || last == 0x80) && v.iter().rev().skip(1).all(|&b| b == 0))
242+
match v.split_last() {
243+
Some((last, rest)) => !((last & !0x80 == 0x00) && rest.iter().all(|&b| b == 0)),
244+
None => false,
245+
}
248246
}
249247

250248
/// Read a script-encoded unsigned integer

0 commit comments

Comments
 (0)