Skip to content

Commit 0b91de1

Browse files
committed
Simplify read_scriptbool
Refactor and simplify the logical operators in `read_scriptbool`. Refactor only, no logic changes.
1 parent 63a0304 commit 0b91de1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/blockdata/script.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,12 @@ 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-
!(v.is_empty() ||
243-
((v[v.len() - 1] == 0 || v[v.len() - 1] == 0x80) &&
244-
v.iter().rev().skip(1).all(|&w| w == 0)))
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))
245248
}
246249

247250
/// Read a script-encoded unsigned integer

0 commit comments

Comments
 (0)