Skip to content
This repository was archived by the owner on Aug 18, 2025. It is now read-only.

Commit 3d9a0ee

Browse files
committed
更新 JIT 编译器中的循环优化策略,添加 Hash 特征以提高类型一致性,并优化循环模式哈希计算方法以提升性能。
1 parent 88d56b7 commit 3d9a0ee

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/interpreter/jit.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::hash::{Hash, Hasher};
1313
use std::collections::hash_map::DefaultHasher;
1414

1515
/// 🔄 v0.7.7: 循环优化策略枚举
16-
#[derive(Debug, Clone, PartialEq)]
16+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1717
pub enum LoopOptimizationStrategy {
1818
/// 循环展开 - 减少循环开销
1919
LoopUnrolling { factor: usize },
@@ -512,12 +512,7 @@ pub struct CompiledArrayOperation {
512512
}
513513

514514
/// 循环类型
515-
#[derive(Debug, Clone, PartialEq)]
516-
pub enum LoopType {
517-
While,
518-
For,
519-
ForEach,
520-
}
515+
521516

522517
/// 循环优化策略
523518
#[derive(Debug, Clone, PartialEq)]
@@ -4138,7 +4133,7 @@ impl JitCompiler {
41384133
}
41394134

41404135
/// 🔄 v0.7.7: 计算循环模式哈希
4141-
pub fn calculate_loop_pattern_hash(&self, loop_body: &[Statement], loop_type: LoopType) -> LoopPatternKey {
4136+
pub fn calculate_loop_pattern_hash(&mut self, loop_body: &[Statement], loop_type: LoopType) -> LoopPatternKey {
41424137
let mut hasher = DefaultHasher::new();
41434138

41444139
// 计算循环体的哈希
@@ -4312,12 +4307,12 @@ impl JitCompiler {
43124307

43134308
// 如果仍然超过限制,移除最少使用的条目
43144309
if self.jit_cache.len() >= self.cache_config.max_cache_entries {
4315-
let mut entries: Vec<_> = self.jit_cache.iter().collect();
4316-
entries.sort_by_key(|(_, cached)| cached.usage_count);
4310+
let mut entries: Vec<_> = self.jit_cache.iter().map(|(k, v)| (k.clone(), v.usage_count)).collect();
4311+
entries.sort_by_key(|(_, usage_count)| *usage_count);
43174312

43184313
let remove_count = self.jit_cache.len() - self.cache_config.max_cache_entries + 1;
43194314
for (key, _) in entries.iter().take(remove_count) {
4320-
self.jit_cache.remove(*key);
4315+
self.jit_cache.remove(key);
43214316
}
43224317
}
43234318

0 commit comments

Comments
 (0)