From 6c3aba1302b50a7ce45a1b7ebaf12a36dcd1936c Mon Sep 17 00:00:00 2001 From: MORITA Kazutaka Date: Sun, 3 May 2020 10:53:30 +0900 Subject: [PATCH 1/2] [RUST][RUNTIME] Fix workspace --- rust/runtime/src/workspace.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/rust/runtime/src/workspace.rs b/rust/runtime/src/workspace.rs index 8344dfbb1adf..77668fe660ae 100644 --- a/rust/runtime/src/workspace.rs +++ b/rust/runtime/src/workspace.rs @@ -64,7 +64,7 @@ impl WorkspacePool { .iter() .fold(None, |cur_ws_idx: Option, &idx| { let ws_size = self.workspaces[idx].size(); - if !ws_size >= size { + if ws_size < size { return cur_ws_idx; } cur_ws_idx.or(Some(idx)).and_then(|cur_idx| { @@ -92,9 +92,8 @@ impl WorkspacePool { break; } } - if let Some(ws_idx) = ws_idx { - self.free.push(ws_idx); - } + let ws_idx = ws_idx.ok_or(format_err!("Invalid pointer"))?; + self.free.push(ws_idx); Ok(()) } } @@ -135,6 +134,5 @@ pub extern "C" fn TVMBackendFreeWorkspace( Ok(()) => 0, Err(_) => -1, }) as c_int - }); - 0 + }) } From 3ef5ca26bc574d871eb5acce84bcbb95596846fd Mon Sep 17 00:00:00 2001 From: MORITA Kazutaka Date: Tue, 5 May 2020 03:11:21 +0900 Subject: [PATCH 2/2] use ok_or_else instead of ok_or --- rust/runtime/src/workspace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/runtime/src/workspace.rs b/rust/runtime/src/workspace.rs index 77668fe660ae..65ad25324cae 100644 --- a/rust/runtime/src/workspace.rs +++ b/rust/runtime/src/workspace.rs @@ -92,7 +92,7 @@ impl WorkspacePool { break; } } - let ws_idx = ws_idx.ok_or(format_err!("Invalid pointer"))?; + let ws_idx = ws_idx.ok_or_else(|| format_err!("Invalid pointer"))?; self.free.push(ws_idx); Ok(()) }