Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lobstr implementation of object_size #488

Merged
merged 4 commits into from
Aug 29, 2024
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
1 change: 1 addition & 0 deletions crates/harp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod r_version;
pub mod raii;
pub mod routines;
pub mod session;
pub mod size;
pub mod string;
pub mod symbol;
pub mod sys;
Expand Down
21 changes: 1 addition & 20 deletions crates/harp/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::exec::RFunction;
use crate::exec::RFunctionExt;
use crate::protect::RProtect;
use crate::r_symbol;
use crate::size::r_size;
use crate::utils::r_assert_capacity;
use crate::utils::r_assert_length;
use crate::utils::r_assert_type;
Expand Down Expand Up @@ -132,26 +133,6 @@ impl<T: Into<RObject>> RObjectExt<T> for RObject {
}
}

// TODO: borrow implementation from lobstr instead
// of calling object.size()
fn r_size(x: SEXP) -> usize {
if r_is_null(x) {
return 0;
}
if r_is_altrep(x) {
return unsafe { r_size(R_altrep_data1(x)) + r_size(R_altrep_data2(x)) };
}
let size = RFunction::new("utils", "object.size").add(x).call();

match size {
Err(_) => 0,
Ok(size) => {
let value = unsafe { REAL_ELT(*size, 0) };
value as usize
},
}
}

pub fn r_length(x: SEXP) -> isize {
unsafe { Rf_xlength(x) }
}
Expand Down
Loading
Loading