Skip to content
Snippets Groups Projects
Unverified Commit 10a3f29f authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Move integer formatting out of a macro

Instead of using a macro to format integer pointers as strings, we can
just use a method. This reduces the (stripped) binary size by about 16
KB.
parent daeb7ab3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -114,30 +114,19 @@ macro_rules! invert_shift {
}};
}
 
/// Converts an integer or a bigint to a String.
macro_rules! format_integer {
($pointer:expr) => {{
if $pointer.is_bigint() {
$pointer.bigint_value()?.to_string()
} else {
$pointer.integer_value()?.to_string()
}
}};
}
/// Generates an error message to display in the event of a shift error.
macro_rules! shift_error {
($to_shift:expr, $shift_with:expr) => {{
if $shift_with.is_integer() || $shift_with.is_bigint() {
format!(
"Can't shift integer {} with {} as the operand is too big",
format_integer!($to_shift),
format_integer!($shift_with)
$to_shift.integer_to_string()?,
$shift_with.integer_to_string()?
)
} else {
format!(
"Can't shift integer {} because the operand is not an integer",
format_integer!($to_shift),
$to_shift.integer_to_string()?,
)
}
}};
Loading
Loading
Loading
Loading
@@ -631,6 +631,16 @@ impl ObjectPointer {
raw: TaggedPointer::new(self.raw.atomic_load()),
}
}
pub fn integer_to_string(&self) -> Result<String, String> {
let string = if self.is_bigint() {
self.bigint_value()?.to_string()
} else {
self.integer_value()?.to_string()
};
Ok(string)
}
}
 
impl ObjectPointerPointer {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment