perf: avoid redundant map lookup in ElectronBrowserContext::From() (#46062)
perf: avoid redundant map lookup in ElectronBrowserContext::FromPath() Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
		
					parent
					
						
							
								463e0d0ab7
							
						
					
				
			
			
				commit
				
					
						3faedae91c
					
				
			
		
					 1 changed files with 10 additions and 21 deletions
				
			
		|  | @ -833,34 +833,23 @@ ElectronBrowserContext* ElectronBrowserContext::From( | ||||||
|     const std::string& partition, |     const std::string& partition, | ||||||
|     bool in_memory, |     bool in_memory, | ||||||
|     base::Value::Dict options) { |     base::Value::Dict options) { | ||||||
|   PartitionKey key(partition, in_memory); |   auto& context = browser_context_map()[PartitionKey(partition, in_memory)]; | ||||||
|   ElectronBrowserContext* browser_context = browser_context_map()[key].get(); |   if (!context) { | ||||||
|   if (browser_context) { |     context.reset(new ElectronBrowserContext{std::cref(partition), in_memory, | ||||||
|     return browser_context; |                                              std::move(options)}); | ||||||
|   } |   } | ||||||
| 
 |   return context.get(); | ||||||
|   auto* new_context = new ElectronBrowserContext(std::cref(partition), |  | ||||||
|                                                  in_memory, std::move(options)); |  | ||||||
|   browser_context_map()[key] = |  | ||||||
|       std::unique_ptr<ElectronBrowserContext>(new_context); |  | ||||||
|   return new_context; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ElectronBrowserContext* ElectronBrowserContext::FromPath( | ElectronBrowserContext* ElectronBrowserContext::FromPath( | ||||||
|     const base::FilePath& path, |     const base::FilePath& path, | ||||||
|     base::Value::Dict options) { |     base::Value::Dict options) { | ||||||
|   PartitionKey key(path); |   auto& context = browser_context_map()[PartitionKey(path)]; | ||||||
| 
 |   if (!context) { | ||||||
|   ElectronBrowserContext* browser_context = browser_context_map()[key].get(); |     context.reset( | ||||||
|   if (browser_context) { |         new ElectronBrowserContext{std::cref(path), false, std::move(options)}); | ||||||
|     return browser_context; |  | ||||||
|   } |   } | ||||||
| 
 |   return context.get(); | ||||||
|   auto* new_context = |  | ||||||
|       new ElectronBrowserContext(std::cref(path), false, std::move(options)); |  | ||||||
|   browser_context_map()[key] = |  | ||||||
|       std::unique_ptr<ElectronBrowserContext>(new_context); |  | ||||||
|   return new_context; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| }  // namespace electron
 | }  // namespace electron
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	![37223003+trop[bot]@users.noreply.github.com](/assets/img/avatar_default.png) trop[bot]
				trop[bot]