Skip to content

Commit

Permalink
Minor "DOM blockers" entropy source optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Finesse committed Jun 23, 2021
1 parent 3242273 commit 4313e6d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/sources/dom_blockers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,20 @@ export function isApplicable(): boolean {
export async function getBlockedSelectors<T extends string>(selectors: readonly T[]): Promise<{ [K in T]?: true }> {
const d = document
const root = d.createElement('div')
const elements: HTMLElement[] = []
const elements = new Array<HTMLElement>(selectors.length)
const blockedSelectors: { [K in T]?: true } = {} // Set() isn't used just in case somebody need older browser support

forceShow(root)

// First create all elements that can be blocked. If the DOM steps below are done in a single cycle,
// browser will alternate tree modification and layout reading, that is very slow.
for (const selector of selectors) {
const element = selectorToElement(selector)
for (let i = 0; i < selectors.length; ++i) {
const element = selectorToElement(selectors[i])
const holder = d.createElement('div') // Protects from unwanted effects of `+` and `~` selectors of filters
forceShow(holder)
holder.appendChild(element)
root.appendChild(holder)
elements.push(element)
elements[i] = element
}

// document.body can be null while the page is loading
Expand Down

0 comments on commit 4313e6d

Please sign in to comment.