Commit 8b4b2409 authored by Mygod's avatar Mygod

Optimize Acl.parse

parent 8f5a460b
...@@ -74,10 +74,13 @@ class Acl { ...@@ -74,10 +74,13 @@ class Acl {
var subnets: MutableList<Subnet>? = if (defaultBypass) proxySubnets else bypassSubnets var subnets: MutableList<Subnet>? = if (defaultBypass) proxySubnets else bypassSubnets
reader.useLines { reader.useLines {
for (line in it) { for (line in it) {
val input = (if (urls == null) line else {
val blocks = line.split('#', limit = 2) val blocks = line.split('#', limit = 2)
val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1) val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1)
if (url != null) urls!!(URL(url)) if (url != null) urls(URL(url))
when (val input = blocks[0].trim()) { blocks[0]
}).trim()
if (input.getOrNull(0) == '[') when (input) {
"[outbound_block_list]" -> { "[outbound_block_list]" -> {
hostnames = null hostnames = null
subnets = null subnets = null
...@@ -92,13 +95,13 @@ class Acl { ...@@ -92,13 +95,13 @@ class Acl {
} }
"[reject_all]", "[bypass_all]" -> bypass = true "[reject_all]", "[bypass_all]" -> bypass = true
"[accept_all]", "[proxy_all]" -> bypass = false "[accept_all]", "[proxy_all]" -> bypass = false
else -> if (subnets != null && input.isNotEmpty()) { else -> error("Unrecognized block: $input")
} else if (subnets != null && input.isNotEmpty()) {
val subnet = Subnet.fromString(input) val subnet = Subnet.fromString(input)
if (subnet == null) hostnames!!(input) else subnets!!.add(subnet) if (subnet == null) hostnames!!(input) else subnets!!.add(subnet)
} }
} }
} }
}
return bypass to if (bypass) proxySubnets else bypassSubnets return bypass to if (bypass) proxySubnets else bypassSubnets
} }
} }
......
...@@ -23,7 +23,6 @@ package com.github.shadowsocks.bg ...@@ -23,7 +23,6 @@ package com.github.shadowsocks.bg
import android.app.Service import android.app.Service
import android.content.Intent import android.content.Intent
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.net.HostsFile import com.github.shadowsocks.net.HostsFile
import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.preference.DataStore
import java.io.File import java.io.File
......
Markdown is supported
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