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 blocks = line.split('#', limit = 2) val input = (if (urls == null) line else {
val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1) val blocks = line.split('#', limit = 2)
if (url != null) urls!!(URL(url)) val url = networkAclParser.matchEntire(blocks.getOrElse(1) { "" })?.groupValues?.getOrNull(1)
when (val input = blocks[0].trim()) { if (url != null) urls(URL(url))
blocks[0]
}).trim()
if (input.getOrNull(0) == '[') when (input) {
"[outbound_block_list]" -> { "[outbound_block_list]" -> {
hostnames = null hostnames = null
subnets = null subnets = null
...@@ -92,10 +95,10 @@ class Acl { ...@@ -92,10 +95,10 @@ 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")
val subnet = Subnet.fromString(input) } else if (subnets != null && input.isNotEmpty()) {
if (subnet == null) hostnames!!(input) else subnets!!.add(subnet) val subnet = Subnet.fromString(input)
} if (subnet == null) hostnames!!(input) else subnets!!.add(subnet)
} }
} }
} }
......
...@@ -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