Commit c0c4a374 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Use array, has less overhead

parent a06cab15
...@@ -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, "")
setOf( arrayOf(
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) {
setOf( arrayOf(
it.replace("**", "%%").replace("*", "%") it.replace("**", "%%").replace("*", "%")
.replace(wildcardNormalisationRegex, "**") .replace(wildcardNormalisationRegex, "**")
) )
} else { } else {
if (it.startsWith("*.")) { if (it.startsWith("*.")) {
setOf( arrayOf(
it.replace(leadingWildcardRegex, ""), it.replace(leadingWildcardRegex, ""),
it.replace(leadingWildcardRegex, "**.").replace("**", "%%") it.replace(leadingWildcardRegex, "**.").replace("**", "%%")
.replace("*", "%%") .replace("*", "%%")
.replace(wildcardNormalisationRegex, "**") .replace(wildcardNormalisationRegex, "**")
) )
} else { } else {
setOf( arrayOf(
it.replace("**", "%%") it.replace("**", "%%")
.replace("*", "%%") .replace("*", "%%")
.replace(wildcardNormalisationRegex, "**") .replace(wildcardNormalisationRegex, "**")
) )
} }
} }
} else setOf(it) } else arrayOf(it)
} }
return alteredHost.map { return alteredHost.map {
DnsRule(type, it, target, targetV6, source.id, isWildcard) DnsRule(type, it, target, targetV6, source.id, isWildcard)
}.toSet() }.toTypedArray()
} }
override fun onDestroy() { override fun onDestroy() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment