Skip to content

Conversation

@guidiaz
Copy link
Contributor

@guidiaz guidiaz commented Sep 8, 2025

No description provided.

@guidiaz guidiaz changed the title Feat/new radon integer operators feat(rpc): new radon integer operators Sep 8, 2025
@guidiaz guidiaz changed the title feat(rpc): new radon integer operators feat(rad): new radon integer operators Sep 8, 2025
@guidiaz guidiaz force-pushed the feat/new-radon-integer-operators branch from b78c193 to 1f79501 Compare September 8, 2025 06:43
@guidiaz guidiaz changed the title feat(rad): new radon integer operators feat(rad): new RadonInteger operators Sep 8, 2025
@guidiaz guidiaz requested a review from aesedepece September 8, 2025 06:48
}
}

pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always assumed that an eventual Integer::to_bytes method would take the preferred endianness as an argument (even if we default to Big Endian)

@guidiaz What do you think?

(RadonOpCodes::IntegerToBytes, None) => integer_operators::to_bytes(self.clone())
.map(RadonTypes::from),
(RadonOpCodes::IntegerToFloat, None) => {
integer_operators::to_float(self.clone()).map(RadonTypes::from)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can stick to Into::into for uniformity:

Suggested change
integer_operators::to_float(self.clone()).map(RadonTypes::from)
integer_operators::to_float(self.clone()).map(Into::into)

}
}

pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, it is better to receive the argument by reference to avoid redundant cloning:

Suggested change
pub fn to_bytes(input: RadonInteger) -> Result<RadonBytes, RadError> {
pub fn to_bytes(input: &RadonInteger) -> Result<RadonBytes, RadError> {

I know you followed what to_float and to_string had in place, but that's not needed anymore with modern Rust 💪

Comment on lines +24 to +25
let mut bytes_array = [0u8; 16];
bytes_array.copy_from_slice(&input.value().to_be_bytes());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work just as well and benefit from lesser allocation and runtime:

Suggested change
let mut bytes_array = [0u8; 16];
bytes_array.copy_from_slice(&input.value().to_be_bytes());
let bytes_array = input.value().to_be_bytes();

@aesedepece
Copy link
Member

Merged as c8f10f8 with optimizations and tests in 69c953f

@aesedepece aesedepece closed this Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants