]> git.lizzy.rs Git - rust.git/commitdiff
suggested rearrangement of the cfg if statements
authorCameron Taggart <cameron.taggart@gmail.com>
Wed, 22 Apr 2020 15:12:44 +0000 (09:12 -0600)
committerGitHub <noreply@github.com>
Wed, 22 Apr 2020 15:12:44 +0000 (09:12 -0600)
Co-Authored-By: ecstatic-morse <ecstaticmorse@gmail.com>
src/librustc_data_structures/profiling.rs

index 1a841cc8a0cfcc05d9f35222187f7ac0d0de9782..e2a1ba3a24b105de81f17df4523246cbd6f33bbd 100644 (file)
@@ -607,41 +607,39 @@ pub fn duration_to_secs_str(dur: std::time::Duration) -> String {
 }
 
 // Memory reporting
-cfg_if! {
-    if #[cfg(target_arch = "wasm32")] {
-        fn get_resident() -> Option<usize> {
-            None
-        }
-    } else {
-        cfg_if! {
-            if #[cfg(windows)] {
-                fn get_resident() -> Option<usize> {
-                    use std::mem::{self, MaybeUninit};
-                    use winapi::shared::minwindef::DWORD;
-                    use winapi::um::processthreadsapi::GetCurrentProcess;
-                    use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
-
-                    let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
-                    match unsafe {
-                        GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
-                    } {
-                        0 => None,
-                        _ => {
-                            let pmc = unsafe { pmc.assume_init() };
-                            Some(pmc.WorkingSetSize as usize)
-                        }
+    cfg_if! {
+        if #[cfg(windows)] {
+            fn get_resident() -> Option<usize> {
+                use std::mem::{self, MaybeUninit};
+                use winapi::shared::minwindef::DWORD;
+                use winapi::um::processthreadsapi::GetCurrentProcess;
+                use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
+
+                let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
+                match unsafe {
+                    GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
+                } {
+                    0 => None,
+                    _ => {
+                        let pmc = unsafe { pmc.assume_init() };
+                        Some(pmc.WorkingSetSize as usize)
                     }
                 }
-            } else {
-                fn get_resident() -> Option<usize> {
-                    let field = 1;
-                    let contents = fs::read("/proc/self/statm").ok()?;
-                    let contents = String::from_utf8(contents).ok()?;
-                    let s = contents.split_whitespace().nth(field)?;
-                    let npages = s.parse::<usize>().ok()?;
-                    Some(npages * 4096)
-                }
             }
+        } else if #[cfg(unix)] {
+            fn get_resident() -> Option<usize> {
+                let field = 1;
+                let contents = fs::read("/proc/self/statm").ok()?;
+                let contents = String::from_utf8(contents).ok()?;
+                let s = contents.split_whitespace().nth(field)?;
+                let npages = s.parse::<usize>().ok()?;
+                Some(npages * 4096)
+            }
+        } else {
+            fn get_resident() -> Option<usize> {
+                None
+            }
+        }
         }
     }
 }