fix: 修复循环字节码哈希错误命中缓存问题
This commit is contained in:
@@ -45,6 +45,19 @@ fn hash_statement(stmt: &Statement, h: &mut rustc_hash::FxHasher) {
|
|||||||
}
|
}
|
||||||
Statement::ForStatement(fr) => {
|
Statement::ForStatement(fr) => {
|
||||||
5u8.hash(h);
|
5u8.hash(h);
|
||||||
|
if let Some(init) = &fr.init {
|
||||||
|
if let Some(expr) = init.as_expression() {
|
||||||
|
hash_expression(expr, h);
|
||||||
|
} else if init.is_var_declaration() {
|
||||||
|
0u8.hash(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(test) = &fr.test {
|
||||||
|
hash_expression(test, h);
|
||||||
|
}
|
||||||
|
if let Some(update) = &fr.update {
|
||||||
|
hash_expression(update, h);
|
||||||
|
}
|
||||||
hash_statement(&fr.body, h);
|
hash_statement(&fr.body, h);
|
||||||
}
|
}
|
||||||
Statement::BlockStatement(block) => {
|
Statement::BlockStatement(block) => {
|
||||||
@@ -89,6 +102,12 @@ fn hash_expression(expr: &Expression, h: &mut rustc_hash::FxHasher) {
|
|||||||
hash_expression(&log.left, h);
|
hash_expression(&log.left, h);
|
||||||
hash_expression(&log.right, h);
|
hash_expression(&log.right, h);
|
||||||
}
|
}
|
||||||
|
Expression::ConditionalExpression(cond) => {
|
||||||
|
4u8.hash(h);
|
||||||
|
hash_expression(&cond.test, h);
|
||||||
|
hash_expression(&cond.consequent, h);
|
||||||
|
hash_expression(&cond.alternate, h);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
std::mem::discriminant(expr).hash(h);
|
std::mem::discriminant(expr).hash(h);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user