Skip to content

Commit 4946d5c

Browse files
Fix lint "unnecessary_casts"
1 parent 4c88de4 commit 4946d5c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/eager/op.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,26 @@ impl<'a> Op<'a> {
160160
/// Sets the value of an attribute which holds a list of strings.
161161
fn set_attr_string_list<S: AsRef<str>>(&mut self, attr_name: &str, values: &[S]) -> Result<()> {
162162
let c_attr_name = CString::new(attr_name)?;
163-
let bytes: Vec<&[u8]> = values.iter().map(|x| x.as_ref().as_bytes()).collect();
164-
let ptrs: Vec<*const c_void> = bytes.iter().map(|x| x.as_ptr() as *const c_void).collect();
165-
let lens: Vec<size_t> = bytes.iter().map(|x| x.len() as size_t).collect();
163+
let (ptrs, lens): (Vec<*const c_void>, Vec<size_t>) = values
164+
.iter()
165+
.map(|entry| {
166+
(
167+
entry.as_ref().as_ptr() as *const std_c_void,
168+
entry.as_ref().len() as size_t,
169+
)
170+
})
171+
.unzip();
172+
166173
unsafe {
167174
tf::TFE_OpSetAttrStringList(
168175
self.inner,
169176
c_attr_name.as_ptr(),
170-
ptrs.as_ptr() as *const *const std_c_void,
177+
ptrs.as_ptr(),
171178
lens.as_ptr(),
172179
ptrs.len() as c_int,
173180
);
174181
}
182+
175183
Ok(())
176184
}
177185

@@ -390,7 +398,7 @@ impl<'a> Op<'a> {
390398
// If the 'num_retvals' was updated, we treat that as an error. See comment above.
391399
if num_retvals != N as i32 {
392400
retvals
393-
.into_iter()
401+
.iter()
394402
.for_each(|retval| unsafe { tf::TFE_DeleteTensorHandle(*retval) });
395403
let status = Status::new_set_lossy(
396404
Code::InvalidArgument,

0 commit comments

Comments
 (0)