Skip to content

Commit

Permalink
Merge #777: feat: remove inefficient if check on match lex
Browse files Browse the repository at this point in the history
aa722c2 feat: remove inefficient if check on match lex (ChrisCho-H)

Pull request description:

  I'm not sure whether it's intentional, but this pattern(match and then if) could make lexer little slower for `OP_CSV` and `OP_CLTV`(and `Error::InvalidOpcode`) as they aren't caught in match arms but `if` block like below(which causes additional check).

  ```rust
  ...
  script::Instruction::Op(op) => {
                  if op == opcodes::all::OP_CSV {
                      ret.push(Token::CheckSequenceVerify);
                  } else if op == opcodes::all::OP_CLTV {
                      ret.push(Token::CheckLockTimeVerify);
                  } else {
                      return Err(Error::InvalidOpcode(op))
                  }
  }
  ```

ACKs for top commit:
  apoelstra:
    ACK aa722c2; successfully ran local tests; nice!
  sanket1729:
    ACK aa722c2

Tree-SHA512: d538e9f064cdb55fc2e8cbb8e56532a0ebe0563e9b1227c9a9a84140e5f23c22663ea2a976a8ac19e69bbbb7eb8b517b54d04ea7759747f2dc8370f5f45f0255
  • Loading branch information
apoelstra committed Nov 25, 2024
2 parents 460400d + aa722c2 commit 76b27da
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/miniscript/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ pub fn lex(script: &'_ script::Script) -> Result<Vec<Token<'_>>, Error> {
ret.push(Token::CheckMultiSig);
ret.push(Token::Verify);
}
script::Instruction::Op(op) if op == opcodes::all::OP_CSV => {
script::Instruction::Op(opcodes::all::OP_CSV) => {
ret.push(Token::CheckSequenceVerify);
}
script::Instruction::Op(op) if op == opcodes::all::OP_CLTV => {
script::Instruction::Op(opcodes::all::OP_CLTV) => {
ret.push(Token::CheckLockTimeVerify);
}
script::Instruction::Op(opcodes::all::OP_FROMALTSTACK) => {
Expand Down

0 comments on commit 76b27da

Please sign in to comment.