mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 20:39:35 +00:00
Optimize release binary size and parse_d_file dependency parsing
This commit is contained in:
@@ -49,3 +49,10 @@ openssl = { version = "0.10", features = ["vendored"] }
|
|||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
git2 = { version = "0.20.4", features = ["vendored-libgit2"] }
|
git2 = { version = "0.20.4", features = ["vendored-libgit2"] }
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "z"
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
strip = true
|
||||||
@@ -329,17 +329,16 @@ pub fn needs_link(objects: &[String], output_path: &str) -> bool {
|
|||||||
|
|
||||||
fn parse_d_file(content: &str) -> Vec<String> {
|
fn parse_d_file(content: &str) -> Vec<String> {
|
||||||
let mut deps = Vec::new();
|
let mut deps = Vec::new();
|
||||||
let text = content.replace("\\\n", " ").replace("\\\r\n", " ");
|
|
||||||
let mut target_end = 0;
|
let mut target_end = 0;
|
||||||
let chars: Vec<char> = text.chars().collect();
|
let bytes = content.as_bytes();
|
||||||
for i in 0..chars.len() {
|
for (i, &b) in bytes.iter().enumerate() {
|
||||||
if chars[i] == ':' {
|
if b == b':' {
|
||||||
if i == 1
|
if i == 1
|
||||||
&& chars[0].is_ascii_alphabetic()
|
&& bytes[0].is_ascii_alphabetic()
|
||||||
&& i + 1 < chars.len()
|
&& i + 1 < bytes.len()
|
||||||
&& (chars[i + 1] == '\\' || chars[i + 1] == '/')
|
&& (bytes[i + 1] == b'\\' || bytes[i + 1] == b'/')
|
||||||
{
|
{
|
||||||
continue; // Windows drive letter
|
continue;
|
||||||
}
|
}
|
||||||
target_end = i + 1;
|
target_end = i + 1;
|
||||||
break;
|
break;
|
||||||
@@ -347,17 +346,23 @@ fn parse_d_file(content: &str) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let deps_str = if target_end > 0 {
|
let deps_str = if target_end > 0 {
|
||||||
&text[target_end..]
|
&content[target_end..]
|
||||||
} else {
|
} else {
|
||||||
&text
|
content
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut current_path = String::new();
|
let mut current_path = String::new();
|
||||||
let mut in_escape = false;
|
let mut in_escape = false;
|
||||||
|
let mut chars = deps_str.chars().peekable();
|
||||||
|
|
||||||
for c in deps_str.chars() {
|
while let Some(c) = chars.next() {
|
||||||
if in_escape {
|
if in_escape {
|
||||||
if c != '\n' && c != '\r' {
|
if c == '\n' {
|
||||||
|
} else if c == '\r' {
|
||||||
|
if chars.peek() == Some(&'\n') {
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
current_path.push(c);
|
current_path.push(c);
|
||||||
}
|
}
|
||||||
in_escape = false;
|
in_escape = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user