mirror of
				https://github.com/NotAShelf/microfetch.git
				synced 2025-11-03 23:32:19 +00:00 
			
		
		
		
	perf: break early after parsing required meminfo
Also a match statement for compiler magic.
This commit is contained in:
		
					parent
					
						
							
								cb9703f820
							
						
					
				
			
			
				commit
				
					
						50827c1847
					
				
			
		
					 1 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
					@ -48,10 +48,16 @@ pub fn get_memory_usage() -> Result<String, io::Error> {
 | 
				
			||||||
        for line in std::fs::read_to_string("/proc/meminfo")?.lines() {
 | 
					        for line in std::fs::read_to_string("/proc/meminfo")?.lines() {
 | 
				
			||||||
            let mut split = line.split_whitespace();
 | 
					            let mut split = line.split_whitespace();
 | 
				
			||||||
            let key = split.next().unwrap_or("");
 | 
					            let key = split.next().unwrap_or("");
 | 
				
			||||||
            if key == "MemTotal:" {
 | 
					
 | 
				
			||||||
                total_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
 | 
					            match key {
 | 
				
			||||||
            } else if key == "MemAvailable:" {
 | 
					                "MemTotal:" => total_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0),
 | 
				
			||||||
                available_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
 | 
					                "MemAvailable:" => {
 | 
				
			||||||
 | 
					                    available_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // MemTotal comes before MemAvailable, stop parsing
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                _ => (),
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue