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
This commit is contained in:
parent
4b6e86658d
commit
df7bb03a67
|
@ -239,12 +239,10 @@ pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
|
||||||
/// else as true", except that the overflow rules don't apply.
|
/// else as true", except that the overflow rules don't apply.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn read_scriptbool(v: &[u8]) -> bool {
|
pub fn read_scriptbool(v: &[u8]) -> bool {
|
||||||
let last = match v.last() {
|
match v.split_last() {
|
||||||
Some(last) => *last,
|
Some((last, rest)) => !((last & !0x80 == 0x00) && rest.iter().all(|&b| b == 0)),
|
||||||
None => return false,
|
None => false,
|
||||||
};
|
}
|
||||||
|
|
||||||
!((last == 0x00 || last == 0x80) && v.iter().rev().skip(1).all(|&b| b == 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a script-encoded unsigned integer
|
/// Read a script-encoded unsigned integer
|
||||||
|
|
Loading…
Reference in New Issue