A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/gorhill/uBlock/commit/725e6931f58a81d36b18bb78663a8740c5e36231 below:

Refactoring work in static network filtering engine · gorhill/uBlock@725e693 · GitHub

@@ -125,7 +125,7 @@ const toSegmentInfo = (aL, l, r) => ((r - l) << 24) | (aL + l);

125 125

const roundToPageSize = v => (v + PAGE_SIZE-1) & ~(PAGE_SIZE-1);

126 126 127 127 128 -

const BidiTrieContainer = class {

128 +

class BidiTrieContainer {

129 129 130 130

constructor(extraHandler) {

131 131

const len = PAGE_SIZE * 4;

@@ -177,6 +177,19 @@ const BidiTrieContainer = class {

177 177

this.lastStoredLen = this.lastStoredIndex = 0;

178 178

}

179 179 180 +

createTrie() {

181 +

// grow buffer if needed

182 +

if ( (this.buf32[CHAR0_SLOT] - this.buf32[TRIE1_SLOT]) < CELL_BYTE_LENGTH ) {

183 +

this.growBuf(CELL_BYTE_LENGTH, 0);

184 +

}

185 +

const iroot = this.buf32[TRIE1_SLOT] >>> 2;

186 +

this.buf32[TRIE1_SLOT] += CELL_BYTE_LENGTH;

187 +

this.buf32[iroot+CELL_OR] = 0;

188 +

this.buf32[iroot+CELL_AND] = 0;

189 +

this.buf32[iroot+SEGMENT_INFO] = 0;

190 +

return iroot;

191 +

}

192 + 180 193

matches(icell, ai) {

181 194

const buf32 = this.buf32;

182 195

const buf8 = this.buf8;

@@ -284,25 +297,9 @@ const BidiTrieContainer = class {

284 297

return 1;

285 298

}

286 299 287 -

createOne(args) {

288 -

if ( Array.isArray(args) ) {

289 -

return new this.STrieRef(this, args[0], args[1]);

290 -

}

291 -

// grow buffer if needed

292 -

if ( (this.buf32[CHAR0_SLOT] - this.buf32[TRIE1_SLOT]) < CELL_BYTE_LENGTH ) {

293 -

this.growBuf(CELL_BYTE_LENGTH, 0);

294 -

}

295 -

const iroot = this.buf32[TRIE1_SLOT] >>> 2;

296 -

this.buf32[TRIE1_SLOT] += CELL_BYTE_LENGTH;

297 -

this.buf32[iroot+CELL_OR] = 0;

298 -

this.buf32[iroot+CELL_AND] = 0;

299 -

this.buf32[iroot+SEGMENT_INFO] = 0;

300 -

return new this.STrieRef(this, iroot, 0);

301 -

}

302 - 303 -

compileOne(trieRef) {

304 -

return [ trieRef.iroot, trieRef.size ];

305 -

}

300 +

get $l() { return this.buf32[RESULT_L_SLOT] | 0; }

301 +

get $r() { return this.buf32[RESULT_R_SLOT] | 0; }

302 +

get $iu() { return this.buf32[RESULT_IU_SLOT] | 0; }

306 303 307 304

add(iroot, aL0, n, pivot = 0) {

308 305

const aR = n;

@@ -561,6 +558,14 @@ const BidiTrieContainer = class {

561 558

}

562 559

}

563 560 561 +

getExtra(iboundary) {

562 +

return this.buf32[iboundary+BCELL_EXTRA];

563 +

}

564 + 565 +

setExtra(iboundary, v) {

566 +

this.buf32[iboundary+BCELL_EXTRA] = v;

567 +

}

568 + 564 569

optimize(shrink = false) {

565 570

if ( shrink ) {

566 571

this.shrinkBuf();

@@ -693,6 +698,65 @@ const BidiTrieContainer = class {

693 698

return -1;

694 699

}

695 700 701 +

dumpTrie(iroot) {

702 +

for ( const s of this.trieIterator(iroot) ) {

703 +

console.log(s);

704 +

}

705 +

}

706 + 707 +

trieIterator(iroot) {

708 +

return {

709 +

value: undefined,

710 +

done: false,

711 +

next() {

712 +

if ( this.icell === 0 ) {

713 +

if ( this.forks.length === 0 ) {

714 +

this.value = undefined;

715 +

this.done = true;

716 +

return this;

717 +

}

718 +

this.charPtr = this.forks.pop();

719 +

this.icell = this.forks.pop();

720 +

}

721 +

for (;;) {

722 +

const idown = this.container.buf32[this.icell+CELL_OR];

723 +

if ( idown !== 0 ) {

724 +

this.forks.push(idown, this.charPtr);

725 +

}

726 +

const v = this.container.buf32[this.icell+SEGMENT_INFO];

727 +

let i0 = this.container.buf32[CHAR0_SLOT] + (v & 0x00FFFFFF);

728 +

const i1 = i0 + (v >>> 24);

729 +

while ( i0 < i1 ) {

730 +

this.charBuf[this.charPtr] = this.container.buf8[i0];

731 +

this.charPtr += 1;

732 +

i0 += 1;

733 +

}

734 +

this.icell = this.container.buf32[this.icell+CELL_AND];

735 +

if ( this.icell === 0 ) {

736 +

return this.toPattern();

737 +

}

738 +

if ( this.container.buf32[this.icell+SEGMENT_INFO] === 0 ) {

739 +

this.icell = this.container.buf32[this.icell+CELL_AND];

740 +

return this.toPattern();

741 +

}

742 +

}

743 +

},

744 +

toPattern() {

745 +

this.value = this.textDecoder.decode(

746 +

new Uint8Array(this.charBuf.buffer, 0, this.charPtr)

747 +

);

748 +

return this;

749 +

},

750 +

container: this,

751 +

icell: iroot,

752 +

charBuf: new Uint8Array(256),

753 +

charPtr: 0,

754 +

forks: [],

755 +

textDecoder: new TextDecoder(),

756 +

[Symbol.iterator]() { return this; },

757 +

};

758 +

}

759 + 696 760

async enableWASM(wasmModuleFetcher, path) {

697 761

if ( typeof WebAssembly !== 'object' ) { return false; }

698 762

if ( this.wasmMemory instanceof WebAssembly.Memory ) { return true; }

@@ -816,103 +880,7 @@ const BidiTrieContainer = class {

816 880

HAYSTACK_START + HAYSTACK_SIZE

817 881

);

818 882

}

819 -

};

820 - 821 -

/*******************************************************************************

822 - 823 -

Class to hold reference to a specific trie

824 - 825 -

*/

826 - 827 -

BidiTrieContainer.prototype.STrieRef = class {

828 -

constructor(container, iroot, size) {

829 -

this.container = container;

830 -

this.iroot = iroot;

831 -

this.size = size;

832 -

}

833 - 834 -

add(i, n, pivot = 0) {

835 -

const iboundary = this.container.add(this.iroot, i, n, pivot);

836 -

if ( iboundary !== 0 ) {

837 -

this.size += 1;

838 -

}

839 -

return iboundary;

840 -

}

841 - 842 -

getExtra(iboundary) {

843 -

return this.container.buf32[iboundary+BCELL_EXTRA];

844 -

}

845 - 846 -

setExtra(iboundary, v) {

847 -

this.container.buf32[iboundary+BCELL_EXTRA] = v;

848 -

}

849 - 850 -

matches(i) {

851 -

return this.container.matches(this.iroot, i);

852 -

}

853 - 854 -

dump() {

855 -

for ( const s of this ) {

856 -

console.log(s);

857 -

}

858 -

}

859 - 860 -

get $l() { return this.container.buf32[RESULT_L_SLOT] | 0; }

861 -

get $r() { return this.container.buf32[RESULT_R_SLOT] | 0; }

862 -

get $iu() { return this.container.buf32[RESULT_IU_SLOT] | 0; }

863 - 864 -

[Symbol.iterator]() {

865 -

return {

866 -

value: undefined,

867 -

done: false,

868 -

next: function() {

869 -

if ( this.icell === 0 ) {

870 -

if ( this.forks.length === 0 ) {

871 -

this.value = undefined;

872 -

this.done = true;

873 -

return this;

874 -

}

875 -

this.charPtr = this.forks.pop();

876 -

this.icell = this.forks.pop();

877 -

}

878 -

for (;;) {

879 -

const idown = this.container.buf32[this.icell+CELL_OR];

880 -

if ( idown !== 0 ) {

881 -

this.forks.push(idown, this.charPtr);

882 -

}

883 -

const v = this.container.buf32[this.icell+SEGMENT_INFO];

884 -

let i0 = this.container.buf32[CHAR0_SLOT] + (v & 0x00FFFFFF);

885 -

const i1 = i0 + (v >>> 24);

886 -

while ( i0 < i1 ) {

887 -

this.charBuf[this.charPtr] = this.container.buf8[i0];

888 -

this.charPtr += 1;

889 -

i0 += 1;

890 -

}

891 -

this.icell = this.container.buf32[this.icell+CELL_AND];

892 -

if ( this.icell === 0 ) {

893 -

return this.toPattern();

894 -

}

895 -

if ( this.container.buf32[this.icell+SEGMENT_INFO] === 0 ) {

896 -

this.icell = this.container.buf32[this.icell+CELL_AND];

897 -

return this.toPattern();

898 -

}

899 -

}

900 -

},

901 -

toPattern: function() {

902 -

this.value = this.textDecoder.decode(

903 -

new Uint8Array(this.charBuf.buffer, 0, this.charPtr)

904 -

);

905 -

return this;

906 -

},

907 -

container: this.container,

908 -

icell: this.iroot,

909 -

charBuf: new Uint8Array(256),

910 -

charPtr: 0,

911 -

forks: [],

912 -

textDecoder: new TextDecoder()

913 -

};

914 -

}

915 -

};

883 +

}

916 884 917 885

/******************************************************************************/

918 886

@@ -954,4 +922,4 @@ const getWasmModule = (( ) => {

954 922 955 923

/******************************************************************************/

956 924 957 -

export { BidiTrieContainer };

925 +

export default BidiTrieContainer;


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4