mirror of
				https://github.com/NotAShelf/microfetch.git
				synced 2025-11-04 07:32:20 +00:00 
			
		
		
		
	release: conditionally improve performance for get_os_pretty_name
		
	It is difficult to get completely accurate benchmarks, given how small the numbers we are dealing with are, but this seems to point at an overall trend of *slightly* faster execution. The change minimizes unnecessary memory allocations and string manipulations, to help ensure more performant line reading and immediate return upon finding the PRETTY_NAME without additional, redundant operations.
This commit is contained in:
		
					parent
					
						
							
								e19abcedae
							
						
					
				
			
			
				commit
				
					
						fd18e9d244
					
				
			
		
					 1 changed files with 7 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -21,7 +21,13 @@ pub fn get_os_pretty_name() -> Result<String, io::Error> {
 | 
			
		|||
    for line in reader.lines() {
 | 
			
		||||
        let line = line?;
 | 
			
		||||
        if let Some(pretty_name) = line.strip_prefix("PRETTY_NAME=") {
 | 
			
		||||
            return Ok(pretty_name.trim_matches('"').to_string());
 | 
			
		||||
            if let Some(trimmed) = pretty_name
 | 
			
		||||
                .strip_prefix('"')
 | 
			
		||||
                .and_then(|s| s.strip_suffix('"'))
 | 
			
		||||
            {
 | 
			
		||||
                return Ok(trimmed.to_string());
 | 
			
		||||
            }
 | 
			
		||||
            return Ok(pretty_name.to_string());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue