txscript: Optimize typeOfScript for witness-script-hash
This concludes the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of witness script hash scripts to use raw script analysis and the new tokenizer. With all of the limbs now useing optimized variants, the following is a before an after comparison of calling GetScriptClass on a large script: benchmark old ns/op new ns/op delta BenchmarkGetScriptClass-8 61515 15.3 -99.98% benchmark old allocs new allocs delta BenchmarkGetScriptClass-8 1 0 -100.00% benchmark old bytes new bytes delta BenchmarkGetScriptClass-8 311299 0 -100.00%
This commit is contained in:
parent
847a262d78
commit
1a60e11da7
1 changed files with 3 additions and 10 deletions
|
@ -441,22 +441,15 @@ func typeOfScript(scriptVersion uint16, script []byte) ScriptClass {
|
|||
return ScriptHashTy
|
||||
case isWitnessPubKeyHashScript(script):
|
||||
return WitnessV0PubKeyHashTy
|
||||
case isWitnessScriptHashScript(script):
|
||||
return WitnessV0ScriptHashTy
|
||||
case isMultisigScript(scriptVersion, script):
|
||||
return MultiSigTy
|
||||
case isNullDataScript(scriptVersion, script):
|
||||
return NullDataTy
|
||||
}
|
||||
|
||||
pops, err := parseScript(script)
|
||||
if err != nil {
|
||||
default:
|
||||
return NonStandardTy
|
||||
}
|
||||
|
||||
if isWitnessScriptHash(pops) {
|
||||
return WitnessV0ScriptHashTy
|
||||
}
|
||||
|
||||
return NonStandardTy
|
||||
}
|
||||
|
||||
// GetScriptClass returns the class of the script passed.
|
||||
|
|
Loading…
Reference in a new issue