Skip to content

Commit

Permalink
Replace all u64/i64 for length, index or offsets into usize/isize
Browse files Browse the repository at this point in the history
On platforms that are 32-bits (or 128?) this should make array and
iterations faster in general. On platforms that are 64-bits, this
will have no effect.
  • Loading branch information
hansl committed Dec 11, 2024
1 parent f5ba695 commit c2a63b8
Show file tree
Hide file tree
Showing 27 changed files with 233 additions and 245 deletions.
16 changes: 4 additions & 12 deletions cli/src/debug/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use boa_engine::{
js_string,
object::{FunctionObjectBuilder, ObjectInitializer},
property::Attribute,
Context, JsArgs, JsNativeError, JsObject, JsResult, JsValue, NativeFunction,
Context, JsArgs, JsObject, JsResult, JsValue, NativeFunction,
};

fn get_loop(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
Expand All @@ -12,7 +12,9 @@ fn get_loop(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsVal

fn set_loop(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
context.runtime_limits_mut().set_loop_iteration_limit(value);
context
.runtime_limits_mut()
.set_loop_iteration_limit(value as u64);
Ok(JsValue::undefined())
}

Expand All @@ -23,11 +25,6 @@ fn get_stack(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<JsVa

fn set_stack(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
let Ok(value) = value.try_into() else {
return Err(JsNativeError::range()
.with_message(format!("Argument {value} greater than usize::MAX"))
.into());
};
context.runtime_limits_mut().set_stack_size_limit(value);
Ok(JsValue::undefined())
}
Expand All @@ -39,11 +36,6 @@ fn get_recursion(_: &JsValue, _: &[JsValue], context: &mut Context) -> JsResult<

fn set_recursion(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult<JsValue> {
let value = args.get_or_undefined(0).to_length(context)?;
let Ok(value) = value.try_into() else {
return Err(JsNativeError::range()
.with_message(format!("Argument {value} greater than usize::MAX"))
.into());
};
context.runtime_limits_mut().set_recursion_limit(value);
Ok(JsValue::undefined())
}
Expand Down
2 changes: 1 addition & 1 deletion core/engine/src/builtins/array/array_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use boa_profiler::Profiler;
#[derive(Debug, Clone, Finalize, Trace, JsData)]
pub(crate) struct ArrayIterator {
array: JsObject,
next_index: u64,
next_index: usize,
#[unsafe_ignore_trace]
kind: PropertyNameKind,
done: bool,
Expand Down
Loading

0 comments on commit c2a63b8

Please sign in to comment.