瀏覽代碼

Preallocate because why not

jD91mZM2 6 年之前
父節點
當前提交
674d4e3695
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      src/unistd/src/lib.rs

+ 9 - 1
src/unistd/src/lib.rs

@@ -173,7 +173,15 @@ pub unsafe extern "C" fn execve(
             env = env.offset(1);
         }
 
-        let mut args: Vec<[usize; 2]> = Vec::new();
+        let mut len = 0;
+        for i in 0.. {
+            if (*arg.offset(i)).is_null() {
+                len = i;
+                break;
+            }
+        }
+
+        let mut args: Vec<[usize; 2]> = Vec::with_capacity(len);
         let mut arg = argv;
         while !(*arg).is_null() {
             args.push([*arg as usize, c_str(*arg).len()]);