Skip to content

Commit

Permalink
Merge pull request shadowsocks#437 from NanaLich/master
Browse files Browse the repository at this point in the history
more unnecessary optimize
  • Loading branch information
GangZhuo committed Feb 6, 2016
2 parents fd67708 + 0e2c28c commit 6a8f554
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
28 changes: 17 additions & 11 deletions shadowsocks-csharp/Controller/Service/GfwListUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ private void http_DownloadStringCompleted(object sender, DownloadStringCompleted
if (File.Exists(PACServer.USER_RULE_FILE))
{
string local = File.ReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8);
string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string rule in rules)
using (var sr = new StringReader(local))
{
if (rule[0] == '!' || rule[0] == '[')
continue;
lines.Add(rule);
string rule;
while ((rule = sr.ReadLine()) != null)
{
if (rule == "" || rule[0] == '!' || rule[0] == '[')
continue;
lines.Add(rule);
}
}
}
string abpContent;
Expand Down Expand Up @@ -93,13 +96,16 @@ public static List<string> ParseResult(string response)
{
byte[] bytes = Convert.FromBase64String(response);
string content = Encoding.ASCII.GetString(bytes);
string[] lines = content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
List<string> valid_lines = new List<string>(lines.Length);
foreach (string line in lines)
List<string> valid_lines = new List<string>();
using (var sr = new StringReader(content))
{
if (line[0] == '!' || line[0] == '[')
continue;
valid_lines.Add(line);
string line;
while ((line = sr.ReadLine()) != null)
{
if (line == "" || line[0] == '!' || line[0] == '[')
continue;
valid_lines.Add(line);
}
}
return valid_lines;
}
Expand Down
13 changes: 8 additions & 5 deletions shadowsocks-csharp/Controller/ShadowsocksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,15 @@ private void pacServer_UserRuleFileChanged(object sender, EventArgs e)
if (File.Exists(PACServer.USER_RULE_FILE))
{
string local = File.ReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8);
string[] rules = local.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string rule in rules)
using (var sr = new StringReader(local))
{
if (rule[0] == '!' || rule[0] == '[')
continue;
lines.Add(rule);
string rule;
while ((rule = sr.ReadLine()) != null)
{
if (rule == "" || rule[0] == '!' || rule[0] == '[')
continue;
lines.Add(rule);
}
}
}
string abpContent;
Expand Down

0 comments on commit 6a8f554

Please sign in to comment.