mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Avoid some redundant stores/loads
This commit is contained in:
parent
5b902b5a49
commit
f86c3f1e7e
1 changed files with 19 additions and 15 deletions
|
@ -1101,21 +1101,26 @@ fn call_with_args<'a, 'ctx, 'env>(
|
||||||
|
|
||||||
debug_assert!(args.len() == 3);
|
debug_assert!(args.len() == 3);
|
||||||
|
|
||||||
let wrapper_struct = args[0].0.into_struct_value();
|
|
||||||
let elem_index = args[1].0.into_int_value();
|
let elem_index = args[1].0.into_int_value();
|
||||||
let (elem, elem_layout) = args[2];
|
let (elem, elem_layout) = args[2];
|
||||||
|
let (wrapper_struct, array_data_ptr) = {
|
||||||
|
// This original wrapper_struct should only stay in scope long enough to clone it.
|
||||||
|
// From then on, we should only ever reference the clone!
|
||||||
|
let wrapper_struct = args[0].0.into_struct_value();
|
||||||
|
|
||||||
// Load the usize length
|
// Load the usize length
|
||||||
let _list_len = load_list_len(builder, wrapper_struct);
|
let list_len = load_list_len(builder, wrapper_struct);
|
||||||
|
|
||||||
// TODO here, check to see if the requested index exceeds the length of the array.
|
// TODO here, check to see if the requested index exceeds the length of the array.
|
||||||
// If so, bail out and return the list unaltered.
|
// If so, bail out and return the list unaltered.
|
||||||
|
|
||||||
// TODO pass the length and data ptr to clone_list, so it doesn't load them twice
|
clone_list(
|
||||||
let wrapper_struct = clone_list(env, wrapper_struct, elem_layout);
|
env,
|
||||||
|
list_len,
|
||||||
// Load the pointer to the elements
|
load_list_ptr(builder, wrapper_struct),
|
||||||
let array_data_ptr = load_list_ptr(builder, wrapper_struct);
|
elem_layout,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
let elem_bytes = elem_layout.stack_size(env.ptr_bytes) as u64;
|
let elem_bytes = elem_layout.stack_size(env.ptr_bytes) as u64;
|
||||||
let elem_size = env.ptr_int().const_int(elem_bytes, false);
|
let elem_size = env.ptr_int().const_int(elem_bytes, false);
|
||||||
|
@ -1212,13 +1217,12 @@ fn load_list_ptr<'ctx>(
|
||||||
|
|
||||||
fn clone_list<'a, 'ctx, 'env>(
|
fn clone_list<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
wrapper_struct: StructValue<'ctx>,
|
list_len: IntValue<'ctx>,
|
||||||
|
elems_ptr: PointerValue<'ctx>,
|
||||||
elem_layout: &Layout<'_>,
|
elem_layout: &Layout<'_>,
|
||||||
) -> StructValue<'ctx> {
|
) -> (StructValue<'ctx>, PointerValue<'ctx>) {
|
||||||
let builder = env.builder;
|
let builder = env.builder;
|
||||||
let ctx = env.context;
|
let ctx = env.context;
|
||||||
let elems_ptr = load_list_ptr(builder, wrapper_struct);
|
|
||||||
let list_len = load_list_len(builder, wrapper_struct);
|
|
||||||
let ptr_bytes = env.ptr_bytes;
|
let ptr_bytes = env.ptr_bytes;
|
||||||
|
|
||||||
// Calculate the number of bytes we'll need to allocate.
|
// Calculate the number of bytes we'll need to allocate.
|
||||||
|
@ -1269,5 +1273,5 @@ fn clone_list<'a, 'ctx, 'env>(
|
||||||
.build_insert_value(struct_val, list_len, Builtin::WRAPPER_LEN, "insert_len")
|
.build_insert_value(struct_val, list_len, Builtin::WRAPPER_LEN, "insert_len")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
struct_val.into_struct_value()
|
(struct_val.into_struct_value(), ptr_val)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue