Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nathan OBrian
Nebulo
Commits
c0c4a374
Commit
c0c4a374
authored
Jun 05, 2021
by
Daniel Wolf
Browse files
Use array, has less overhead
parent
a06cab15
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/RuleImportService.kt
View file @
c0c4a374
...
@@ -368,7 +368,7 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -368,7 +368,7 @@ class RuleImportService : IntentService("RuleImportService") {
}
}
private
val
wwwRegex
=
Regex
(
"^www\\."
)
private
val
wwwRegex
=
Regex
(
"^www\\."
)
private
fun
processLine
(
matcher
:
Matcher
,
source
:
HostSource
,
isWhitelist
:
Boolean
):
Set
<
DnsRule
>
{
private
fun
processLine
(
matcher
:
Matcher
,
source
:
HostSource
,
isWhitelist
:
Boolean
):
Array
<
DnsRule
>
{
val
defaultTargetV4
=
if
(
isWhitelist
)
""
else
"0"
val
defaultTargetV4
=
if
(
isWhitelist
)
""
else
"0"
val
defaultTargetV6
=
if
(
isWhitelist
)
""
else
"1"
val
defaultTargetV6
=
if
(
isWhitelist
)
""
else
"1"
when
{
when
{
...
@@ -393,7 +393,7 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -393,7 +393,7 @@ class RuleImportService : IntentService("RuleImportService") {
matcher
==
hostsMatcher
->
{
matcher
==
hostsMatcher
->
{
return
if
(
isWhitelist
)
{
return
if
(
isWhitelist
)
{
val
host
=
matcher
.
group
(
2
)
!!
.
replace
(
wwwRegex
,
""
)
val
host
=
matcher
.
group
(
2
)
!!
.
replace
(
wwwRegex
,
""
)
set
Of
(
array
Of
(
DnsRule
(
DnsRule
(
Record
.
TYPE
.
ANY
,
Record
.
TYPE
.
ANY
,
host
,
host
,
...
@@ -428,37 +428,37 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -428,37 +428,37 @@ class RuleImportService : IntentService("RuleImportService") {
targetV6
:
String
?
=
null
,
targetV6
:
String
?
=
null
,
type
:
Record
.
TYPE
,
type
:
Record
.
TYPE
,
source
:
HostSource
source
:
HostSource
):
Set
<
DnsRule
>
{
):
Array
<
DnsRule
>
{
var
isWildcard
=
false
var
isWildcard
=
false
val
alteredHost
:
Set
<
String
>
=
host
.
let
{
val
alteredHost
:
Array
<
String
>
=
host
.
let
{
if
(
it
.
contains
(
"*"
))
{
if
(
it
.
contains
(
"*"
))
{
isWildcard
=
true
isWildcard
=
true
if
(
source
.
isFileSource
)
{
if
(
source
.
isFileSource
)
{
set
Of
(
array
Of
(
it
.
replace
(
"**"
,
"%%"
).
replace
(
"*"
,
"%"
)
it
.
replace
(
"**"
,
"%%"
).
replace
(
"*"
,
"%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
)
}
else
{
}
else
{
if
(
it
.
startsWith
(
"*."
))
{
if
(
it
.
startsWith
(
"*."
))
{
set
Of
(
array
Of
(
it
.
replace
(
leadingWildcardRegex
,
""
),
it
.
replace
(
leadingWildcardRegex
,
""
),
it
.
replace
(
leadingWildcardRegex
,
"**."
).
replace
(
"**"
,
"%%"
)
it
.
replace
(
leadingWildcardRegex
,
"**."
).
replace
(
"**"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
)
}
else
{
}
else
{
set
Of
(
array
Of
(
it
.
replace
(
"**"
,
"%%"
)
it
.
replace
(
"**"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
)
}
}
}
}
}
else
set
Of
(
it
)
}
else
array
Of
(
it
)
}
}
return
alteredHost
.
map
{
return
alteredHost
.
map
{
DnsRule
(
type
,
it
,
target
,
targetV6
,
source
.
id
,
isWildcard
)
DnsRule
(
type
,
it
,
target
,
targetV6
,
source
.
id
,
isWildcard
)
}.
to
Set
()
}.
to
TypedArray
()
}
}
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment