Cache last 100 getDomains for filterStyles
This commit is contained in:
		
							parent
							
								
									78c56352cb
								
							
						
					
					
						commit
						4a642f77a5
					
				
							
								
								
									
										15
									
								
								storage.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								storage.js
									
									
									
									
									
								
							|  | @ -37,6 +37,7 @@ var cachedStyles, prefs; | ||||||
|     byId: new Map(), |     byId: new Map(), | ||||||
|     filters: new Map(), |     filters: new Map(), | ||||||
|     regexps: new Map(), |     regexps: new Map(), | ||||||
|  |     urlDomains: new Map(), | ||||||
|     mutex: { |     mutex: { | ||||||
|       inProgress: false, |       inProgress: false, | ||||||
|       onDone: [], |       onDone: [], | ||||||
|  | @ -196,6 +197,14 @@ function filterStyles(options = {}) { | ||||||
|       : cached.styles; |       : cached.styles; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   if (matchUrl && !cachedStyles.urlDomains.has(matchUrl)) { | ||||||
|  |     cachedStyles.urlDomains.set(matchUrl, getDomains(matchUrl)); | ||||||
|  |     for (let i = cachedStyles.urlDomains.size - 100; i > 0; i--) { | ||||||
|  |       const firstKey = cachedStyles.urlDomains.keys().next().value; | ||||||
|  |       cachedStyles.urlDomains.delete(firstKey); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   const styles = id === null |   const styles = id === null | ||||||
|     ? (code ? cachedStyles.list : cachedStyles.noCode) |     ? (code ? cachedStyles.list : cachedStyles.noCode) | ||||||
|     : [(cachedStyles.byId.get(id) || {})[code ? 'style' : 'noCode']]; |     : [(cachedStyles.byId.get(id) || {})[code ? 'style' : 'noCode']]; | ||||||
|  | @ -457,13 +466,12 @@ function sectionAppliesToUrl(section, url) { | ||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (section.domains.length) { |   const urlDomains = cachedStyles.urlDomains.get(url) || getDomains(url); | ||||||
|     for (const domain of getDomains(url)) { |   for (const domain of urlDomains) { | ||||||
|     if (section.domains.indexOf(domain) != -1) { |     if (section.domains.indexOf(domain) != -1) { | ||||||
|       return true; |       return true; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   } |  | ||||||
|   for (const regexp of section.regexps) { |   for (const regexp of section.regexps) { | ||||||
|     let rx = cachedStyles.regexps.get(regexp); |     let rx = cachedStyles.regexps.get(regexp); | ||||||
|     if (rx == false) { |     if (rx == false) { | ||||||
|  | @ -490,6 +498,7 @@ function isCheckbox(el) { | ||||||
|   return el.localName == 'input' && el.type == 'checkbox'; |   return el.localName == 'input' && el.type == 'checkbox'; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| // js engine can't optimize the entire function if it contains try-catch
 | // js engine can't optimize the entire function if it contains try-catch
 | ||||||
| // so we should keep it isolated from normal code in a minimal wrapper
 | // so we should keep it isolated from normal code in a minimal wrapper
 | ||||||
| // Update: might get fixed in V8 TurboFan in the future
 | // Update: might get fixed in V8 TurboFan in the future
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user