Skip to content

Commit feea6b7

Browse files
CopilotashyanSpada
andauthored
Consolidate Bolt PRs: optimize Context lock usage and eliminate redundant ContextValue clones (#59)
* Initial plan * Optimize Context lookups: inline lock and match on borrowed refs in get_func/get_variable/value Agent-Logs-Url: https://github.com/ashyanSpada/expression_engine_rs/sessions/7e9ce6a0-1aa8-4510-9420-d73ff44eee82 Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
1 parent f50ac5d commit feea6b7

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

src/context.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ impl Context {
3131
}
3232

3333
pub fn get_func(&self, name: &str) -> Option<Arc<InnerFunction>> {
34-
let value = self.get(name)?;
35-
match value {
36-
ContextValue::Function(func) => Some(func),
34+
let binding = self.0.lock().unwrap();
35+
match binding.get(name)? {
36+
ContextValue::Function(func) => Some(func.clone()),
3737
ContextValue::Variable(_) => None,
3838
}
3939
}
4040

4141
pub fn get_variable(&self, name: &str) -> Option<Value> {
42-
let value = self.get(name)?;
43-
match value {
44-
ContextValue::Variable(v) => Some(v),
42+
let binding = self.0.lock().unwrap();
43+
match binding.get(name)? {
44+
ContextValue::Variable(v) => Some(v.clone()),
4545
ContextValue::Function(_) => None,
4646
}
4747
}
@@ -51,13 +51,15 @@ impl Context {
5151
}
5252

5353
pub fn value(&self, name: &str) -> Result<Value> {
54-
// Lock is acquired and released inside `get` early to avoid contention during execution
55-
let value = self.get(name);
56-
match value {
57-
Some(ContextValue::Variable(v)) => Ok(v),
58-
Some(ContextValue::Function(func)) => func(Vec::new()),
59-
None => Ok(Value::None),
60-
}
54+
let func = {
55+
let binding = self.0.lock().unwrap();
56+
match binding.get(name) {
57+
Some(ContextValue::Variable(v)) => return Ok(v.clone()),
58+
Some(ContextValue::Function(func)) => func.clone(),
59+
None => return Ok(Value::None),
60+
}
61+
};
62+
func(Vec::new())
6163
}
6264
}
6365

0 commit comments

Comments
 (0)