split filterStyles()
js engines don't like big functions (V8 often deoptimized the original filterStyles), it also makes sense to extract the less frequently executed code
This commit is contained in:
		
							parent
							
								
									dcfb8ad356
								
							
						
					
					
						commit
						fa46a2c336
					
				
							
								
								
									
										29
									
								
								storage.js
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								storage.js
									
									
									
									
									
								
							|  | @ -110,12 +110,36 @@ function filterStyles({ | ||||||
|   if (cached) { |   if (cached) { | ||||||
|     cached.hits++; |     cached.hits++; | ||||||
|     cached.lastHit = Date.now(); |     cached.lastHit = Date.now(); | ||||||
| 
 |  | ||||||
|     return asHash |     return asHash | ||||||
|       ? Object.assign({disableAll}, cached.styles) |       ? Object.assign({disableAll}, cached.styles) | ||||||
|       : cached.styles; |       : cached.styles; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   return filterStylesInternal({ | ||||||
|  |     enabled, | ||||||
|  |     url, | ||||||
|  |     id, | ||||||
|  |     matchUrl, | ||||||
|  |     asHash, | ||||||
|  |     strictRegexp, | ||||||
|  |     disableAll, | ||||||
|  |     cacheKey, | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | function filterStylesInternal({ | ||||||
|  |   // js engines don't like big functions (V8 often deoptimized the original filterStyles)
 | ||||||
|  |   // it also makes sense to extract the less frequently executed code
 | ||||||
|  |   enabled, | ||||||
|  |   url, | ||||||
|  |   id, | ||||||
|  |   matchUrl, | ||||||
|  |   asHash, | ||||||
|  |   strictRegexp, | ||||||
|  |   disableAll, | ||||||
|  |   cacheKey, | ||||||
|  | }) { | ||||||
|   if (matchUrl && !cachedStyles.urlDomains.has(matchUrl)) { |   if (matchUrl && !cachedStyles.urlDomains.has(matchUrl)) { | ||||||
|     cachedStyles.urlDomains.set(matchUrl, getDomains(matchUrl)); |     cachedStyles.urlDomains.set(matchUrl, getDomains(matchUrl)); | ||||||
|     for (let i = cachedStyles.urlDomains.size - 100; i > 0; i--) { |     for (let i = cachedStyles.urlDomains.size - 100; i > 0; i--) { | ||||||
|  | @ -133,6 +157,7 @@ function filterStyles({ | ||||||
|     // of edit.html with a non-existent style id parameter
 |     // of edit.html with a non-existent style id parameter
 | ||||||
|     return filtered; |     return filtered; | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|   const needSections = asHash || matchUrl !== null; |   const needSections = asHash || matchUrl !== null; | ||||||
| 
 | 
 | ||||||
|   for (let i = 0, style; (style = styles[i]); i++) { |   for (let i = 0, style; (style = styles[i]); i++) { | ||||||
|  | @ -150,6 +175,7 @@ function filterStyles({ | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|   cachedStyles.filters.set(cacheKey, { |   cachedStyles.filters.set(cacheKey, { | ||||||
|     styles: filtered, |     styles: filtered, | ||||||
|     lastHit: Date.now(), |     lastHit: Date.now(), | ||||||
|  | @ -158,6 +184,7 @@ function filterStyles({ | ||||||
|   if (cachedStyles.filters.size > 10000) { |   if (cachedStyles.filters.size > 10000) { | ||||||
|     cleanupCachedFilters(); |     cleanupCachedFilters(); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|   return asHash |   return asHash | ||||||
|     ? Object.assign({disableAll}, filtered) |     ? Object.assign({disableAll}, filtered) | ||||||
|     : filtered; |     : filtered; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user