bench/comparison/blockers/ublock/publicsuffixlist.js
function() {
    const buf8 = pslBuffer8;
    const buf32 = pslBuffer32;
    const iCharData = buf32[CHARDATA_PTR_SLOT];

    let iNode = pslBuffer32[RULES_PTR_SLOT];
    let cursorPos = -1;
    let iLabel = LABEL_INDICES_SLOT;

    // Label-lookup loop
    for (;;) {
        // Extract label indices
        const labelBeg = buf8[iLabel+1];
        const labelLen = buf8[iLabel+0] - labelBeg;
        // Match-lookup loop: binary search
        let r = buf32[iNode+0] >>> 16;
        if ( r === 0 ) { break; }
        const iCandidates = buf32[iNode+2];
        let l = 0;
        let iFound = 0;
        while ( l < r ) {
            const iCandidate = l + r >>> 1;
            const iCandidateNode = iCandidates + iCandidate + (iCandidate << 1);
            const candidateLen = buf32[iCandidateNode+0] & 0x000000FF;
            let d = labelLen - candidateLen;
            if ( d === 0 ) {
                const iCandidateChar = candidateLen <= 4
                    ? iCandidateNode + 1 << 2
                    : iCharData + buf32[iCandidateNode+1];
                for ( let i = 0; i < labelLen; i++ ) {
                    d = buf8[labelBeg+i] - buf8[iCandidateChar+i];
                    if ( d !== 0 ) { break; }
                }
            }
            if ( d < 0 ) {
                r = iCandidate;
            } else if ( d > 0 ) {
                l = iCandidate + 1;
            } else /* if ( d === 0 ) */ {
                iFound = iCandidateNode;
                break;
            }
        }
        // 2. If no rules match, the prevailing rule is "*".
        if ( iFound === 0 ) {
            if ( buf8[iCandidates + 1 << 2] !== 0x2A /* '*' */ ) { break; }
            iFound = iCandidates;
        }
        iNode = iFound;
        // 5. If the prevailing rule is a exception rule, modify it by
        //    removing the leftmost label.
        if ( (buf32[iNode+0] & 0x00000200) !== 0 ) {
            if ( iLabel > LABEL_INDICES_SLOT ) {
                return iLabel - 2;
            }
            break;
        }
        if ( (buf32[iNode+0] & 0x00000100) !== 0 ) {
            cursorPos = iLabel;
        }
        if ( labelBeg === 0 ) { break; }
        iLabel += 2;
    }

    return cursorPos;
}
function() {
    const buf8 = pslBuffer8;
    const buf32 = pslBuffer32;
    const iCharData = buf32[CHARDATA_PTR_SLOT];

    let iNode = pslBuffer32[RULES_PTR_SLOT];
    let cursorPos = -1;
    let iLabel = LABEL_INDICES_SLOT;

    // Label-lookup loop
    for (;;) {
        // Extract label indices
        const labelBeg = buf8[iLabel+1];
        const labelLen = buf8[iLabel+0] - labelBeg;
        // Match-lookup loop: binary search
        let r = buf32[iNode+0] >>> 16;
        if ( r === 0 ) { break; }
        const iCandidates = buf32[iNode+2];
        let l = 0;
        let iFound = 0;
        while ( l < r ) {
            const iCandidate = l + r >>> 1;
            const iCandidateNode = iCandidates + iCandidate + (iCandidate << 1);
            const candidateLen = buf32[iCandidateNode+0] & 0x000000FF;
            let d = labelLen - candidateLen;
            if ( d === 0 ) {
                const iCandidateChar = candidateLen <= 4
                    ? iCandidateNode + 1 << 2
                    : iCharData + buf32[iCandidateNode+1];
                for ( let i = 0; i < labelLen; i++ ) {
                    d = buf8[labelBeg+i] - buf8[iCandidateChar+i];
                    if ( d !== 0 ) { break; }
                }
            }
            if ( d < 0 ) {
                r = iCandidate;
            } else if ( d > 0 ) {
                l = iCandidate + 1;
            } else /* if ( d === 0 ) */ {
                iFound = iCandidateNode;
                break;
            }
        }
        // 2. If no rules match, the prevailing rule is "*".
        if ( iFound === 0 ) {
            if ( buf8[iCandidates + 1 << 2] !== 0x2A /* '*' */ ) { break; }
            iFound = iCandidates;
        }
        iNode = iFound;
        // 5. If the prevailing rule is a exception rule, modify it by
        //    removing the leftmost label.
        if ( (buf32[iNode+0] & 0x00000200) !== 0 ) {
            if ( iLabel > LABEL_INDICES_SLOT ) {
                return iLabel - 2;
            }
            break;
        }
        if ( (buf32[iNode+0] & 0x00000100) !== 0 ) {
            cursorPos = iLabel;
        }
        if ( labelBeg === 0 ) { break; }
        iLabel += 2;
    }

    return cursorPos;
}
function ( ) { const buf8 = pslBuffer8 ; const buf32 = pslBuffer32 ; const iCharData = buf32 [ CHARDATA_PTR_SLOT ] ; let iNode = pslBuffer32 [ RULES_PTR_SLOT ] ; let cursorPos = - 1 ; let iLabel = LABEL_INDICES_SLOT ; // Label-lookup loop for ( ; ; ) { // Extract label indices const labelBeg = buf8 [ iLabel + 1 ] ; const labelLen = buf8 [ iLabel + 0 ] - labelBeg ; // Match-lookup loop: binary search let r = buf32 [ iNode + 0 ] >>> 16 ; if ( r === 0 ) { break ; } const iCandidates = buf32 [ iNode + 2 ] ; let l = 0 ; let iFound = 0 ; while ( l < r ) { const iCandidate = l + r >>> 1 ; const iCandidateNode = iCandidates + iCandidate + ( iCandidate << 1 ) ; const candidateLen = buf32 [ iCandidateNode + 0 ] & 0x000000FF ; let d = labelLen - candidateLen ; if ( d === 0 ) { const iCandidateChar = candidateLen <= 4 ? iCandidateNode + 1 << 2 : iCharData + buf32 [ iCandidateNode + 1 ] ; for ( let i = 0 ; i < labelLen ; i ++ ) { d = buf8 [ labelBeg + i ] - buf8 [ iCandidateChar + i ] ; if ( d !== 0 ) { break ; } } } if ( d < 0 ) { r = iCandidate ; } else if ( d > 0 ) { l = iCandidate + 1 ; } else /* if ( d === 0 ) */ { iFound = iCandidateNode ; break ; } } // 2. If no rules match, the prevailing rule is "*". if ( iFound === 0 ) { if ( buf8 [ iCandidates + 1 << 2 ] !== 0x2A /* '*' */ ) { break ; } iFound = iCandidates ; } iNode = iFound ; // 5. If the prevailing rule is a exception rule, modify it by //    removing the leftmost label. if ( ( buf32 [ iNode + 0 ] & 0x00000200 ) !== 0 ) { if ( iLabel > LABEL_INDICES_SLOT ) { return iLabel - 2 ; } break ; } if ( ( buf32 [ iNode + 0 ] & 0x00000100 ) !== 0 ) { cursorPos = iLabel ; } if ( labelBeg === 0 ) { break ; } iLabel += 2 ; } return cursorPos ; }
Returns an offset to the start of the public suffix.  WASM-able, because no information outside the buffer content is required.
Returns an offset to the start of the public suffix . WASM - able because no information outside the buffer content is required .