@@ -679,6 +679,9 @@ var FilterContainer = function() {
679679 this . supportedFilterCount = 0 ;
680680 this . allowFilterCount = 0 ;
681681 this . blockFilterCount = 0 ;
682+
683+ // Used during URL matching
684+ this . categoryBuckets = new Array ( 8 ) ;
682685} ;
683686
684687/******************************************************************************/
@@ -1048,11 +1051,7 @@ FilterContainer.prototype.freeze = function() {
10481051
10491052/******************************************************************************/
10501053
1051- FilterContainer . prototype . matchToken = function ( category ) {
1052- var categoryBucket = this . categories [ this . makeCategoryKey ( category ) ] ;
1053- if ( categoryBucket === undefined ) {
1054- return false ;
1055- }
1054+ FilterContainer . prototype . matchToken = function ( categoryBucket ) {
10561055 var url = this . url ;
10571056 var beg = this . tokenBeg ;
10581057 var end = this . tokenEnd ;
@@ -1127,32 +1126,44 @@ FilterContainer.prototype.matchString = function(pageStats, url, requestType, re
11271126 ThirdParty ;
11281127 var domainParty = this . toDomainBits ( pageDomain ) ;
11291128 var type = typeNameToTypeValue [ requestType ] ;
1130- var bf = false ;
11311129
11321130 // This will be used by hostname-based filter
11331131 pageHostname = pageStats . pageHostname ;
11341132
1133+ var categories = this . categories ;
1134+ var categoryBuckets = this . categoryBuckets ;
1135+ var i , categoryBucket ;
1136+
11351137 // Test against block filters
1138+ categoryBuckets [ 7 ] = categories [ this . makeCategoryKey ( BlockAnyTypeAnyParty ) ] ;
1139+ categoryBuckets [ 6 ] = categories [ this . makeCategoryKey ( BlockAnyType | party ) ] ;
1140+ categoryBuckets [ 5 ] = categories [ this . makeCategoryKey ( BlockAnyTypeOneParty | domainParty ) ] ;
1141+ categoryBuckets [ 4 ] = categories [ this . makeCategoryKey ( BlockAnyTypeOtherParties | domainParty ) ] ;
1142+ categoryBuckets [ 3 ] = categories [ this . makeCategoryKey ( BlockAnyParty | type ) ] ;
1143+ categoryBuckets [ 2 ] = categories [ this . makeCategoryKey ( BlockAction | type | party ) ] ;
1144+ categoryBuckets [ 1 ] = categories [ this . makeCategoryKey ( BlockOneParty | type | domainParty ) ] ;
1145+ categoryBuckets [ 0 ] = categories [ this . makeCategoryKey ( BlockOtherParties | type | domainParty ) ] ;
1146+
1147+ var bf = false ;
1148+
11361149 reAnyToken . lastIndex = 0 ;
11371150 while ( matches = reAnyToken . exec ( url ) ) {
11381151 this . tokenBeg = matches . index ;
11391152 this . tokenEnd = reAnyToken . lastIndex ;
1140- bf = this . matchToken ( BlockAnyTypeAnyParty ) ;
1141- if ( bf !== false ) { break ; }
1142- bf = this . matchToken ( BlockAnyType | party ) ;
1143- if ( bf !== false ) { break ; }
1144- bf = this . matchToken ( BlockAnyTypeOneParty | domainParty ) ;
1145- if ( bf !== false ) { break ; }
1146- bf = this . matchToken ( BlockAnyTypeOtherParties | domainParty ) ;
1147- if ( bf !== false ) { break ; }
1148- bf = this . matchToken ( BlockAnyParty | type ) ;
1149- if ( bf !== false ) { break ; }
1150- bf = this . matchToken ( BlockAction | type | party ) ;
1151- if ( bf !== false ) { break ; }
1152- bf = this . matchToken ( BlockOneParty | type | domainParty ) ;
1153- if ( bf !== false ) { break ; }
1154- bf = this . matchToken ( BlockOtherParties | type | domainParty ) ;
1155- if ( bf !== false ) { break ; }
1153+ i = 8 ;
1154+ while ( i -- ) {
1155+ categoryBucket = categoryBuckets [ i ] ;
1156+ if ( categoryBucket === undefined ) {
1157+ continue ;
1158+ }
1159+ bf = this . matchToken ( categoryBucket ) ;
1160+ if ( bf !== false ) {
1161+ break ;
1162+ }
1163+ }
1164+ if ( bf !== false ) {
1165+ break ;
1166+ }
11561167 }
11571168
11581169 // If there was no block filter, no need to test against allow filters
@@ -1161,26 +1172,29 @@ FilterContainer.prototype.matchString = function(pageStats, url, requestType, re
11611172 }
11621173
11631174 // Test against allow filters
1175+ categoryBuckets [ 7 ] = categories [ this . makeCategoryKey ( AllowAnyTypeAnyParty ) ] ;
1176+ categoryBuckets [ 6 ] = categories [ this . makeCategoryKey ( AllowAnyType | party ) ] ;
1177+ categoryBuckets [ 5 ] = categories [ this . makeCategoryKey ( AllowAnyTypeOneParty | domainParty ) ] ;
1178+ categoryBuckets [ 4 ] = categories [ this . makeCategoryKey ( AllowAnyTypeOtherParties | domainParty ) ] ;
1179+ categoryBuckets [ 3 ] = categories [ this . makeCategoryKey ( AllowAnyParty | type ) ] ;
1180+ categoryBuckets [ 2 ] = categories [ this . makeCategoryKey ( AllowAction | type | party ) ] ;
1181+ categoryBuckets [ 1 ] = categories [ this . makeCategoryKey ( AllowOneParty | type | domainParty ) ] ;
1182+ categoryBuckets [ 0 ] = categories [ this . makeCategoryKey ( AllowOtherParties | type | domainParty ) ] ;
1183+
11641184 reAnyToken . lastIndex = 0 ;
11651185 while ( matches = reAnyToken . exec ( url ) ) {
11661186 this . tokenBeg = matches . index ;
11671187 this . tokenEnd = reAnyToken . lastIndex ;
1168- if ( this . matchToken ( AllowAnyTypeAnyParty ) !== false )
1169- { return false ; }
1170- if ( this . matchToken ( AllowAnyType | party ) !== false )
1171- { return false ; }
1172- if ( this . matchToken ( AllowAnyTypeOneParty | domainParty ) !== false )
1173- { return false ; }
1174- if ( this . matchToken ( AllowAnyTypeOtherParties | domainParty ) !== false )
1175- { return false ; }
1176- if ( this . matchToken ( AllowAnyParty | type ) !== false )
1177- { return false ; }
1178- if ( this . matchToken ( AllowAction | type | party ) !== false )
1179- { return false ; }
1180- if ( this . matchToken ( AllowOneParty | type | domainParty ) !== false )
1181- { return false ; }
1182- if ( this . matchToken ( AllowOtherParties | type | domainParty ) !== false )
1183- { return false ; }
1188+ i = 8 ;
1189+ while ( i -- ) {
1190+ categoryBucket = categoryBuckets [ i ] ;
1191+ if ( categoryBucket === undefined ) {
1192+ continue ;
1193+ }
1194+ if ( this . matchToken ( categoryBucket ) !== false ) {
1195+ return false ;
1196+ }
1197+ }
11841198 }
11851199
11861200 return bf ;
0 commit comments