Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions stdlib/src/async_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl StdlibRegistry {
arity: 1,
callback: |_ctx, args| {
let callback = args[0].clone();
let mut fut_map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut fut_map = IndexMap::with_capacity(2);
fut_map.insert(
"state".to_string(),
RuntimeValue::Str("pending".to_string()),
Expand Down Expand Up @@ -68,7 +69,8 @@ impl StdlibRegistry {
name: "make_future".to_string(),
arity: 0,
callback: |_ctx, _args| {
let mut fut_map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut fut_map = IndexMap::with_capacity(2);
fut_map.insert(
"state".to_string(),
RuntimeValue::Str("pending".to_string()),
Expand Down Expand Up @@ -106,7 +108,8 @@ impl StdlibRegistry {
let (tx, rx) = std::sync::mpsc::channel::<RuntimeValue>();
let tx_id = ctx.resources.borrow_mut().insert(tx);
let rx_id = ctx.resources.borrow_mut().insert(rx);
let mut map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut map = IndexMap::with_capacity(2);
map.insert("_tx_handle".to_string(), RuntimeValue::Int(tx_id as i64));
map.insert("_rx_handle".to_string(), RuntimeValue::Int(rx_id as i64));
Ok(RuntimeValue::Map {
Expand Down
6 changes: 4 additions & 2 deletions stdlib/src/net_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub fn tcp_listen_fn(
)
})?;
let handle_id = ctx.resources.borrow_mut().insert(listener);
let mut listener_map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut listener_map = IndexMap::with_capacity(2);
listener_map.insert("port".to_string(), RuntimeValue::Int(port));
listener_map.insert("_handle".to_string(), RuntimeValue::Int(handle_id as i64));
Ok(RuntimeValue::Map {
Expand All @@ -43,7 +44,8 @@ pub fn tcp_connect_fn(
)
})?;
let handle_id = ctx.resources.borrow_mut().insert(stream);
let mut stream_map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut stream_map = IndexMap::with_capacity(3);
stream_map.insert("ip".to_string(), RuntimeValue::Str(ip));
stream_map.insert("port".to_string(), RuntimeValue::Int(port));
stream_map.insert("_handle".to_string(), RuntimeValue::Int(handle_id as i64));
Expand Down
3 changes: 2 additions & 1 deletion stdlib/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ fn process_run(
)
})?;

let mut res_map = IndexMap::new();
// ⚑ Bolt Performance Optimization: Pre-allocated IndexMap capacity to avoid re-hashing during insertion.
let mut res_map = IndexMap::with_capacity(3);
res_map.insert(
"stdout".to_string(),
RuntimeValue::Str(String::from_utf8_lossy(&output.stdout).to_string()),
Expand Down
Loading