about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-24 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-01-27 12:08:53 +0100
commita6137fb730d59141ff2f5744b6cf36e29ef74e94 (patch)
treee4dfa4a9526038ec2664f103844b395d22b23eef
parent320ada6479b3e29c7d9a66bc56ac44c2d2b57566 (diff)
downloadrust-a6137fb730d59141ff2f5744b6cf36e29ef74e94.tar.gz
rust-a6137fb730d59141ff2f5744b6cf36e29ef74e94.zip
compiletest: Remove unnecessary memory allocation in iter_header
Replace `BufRead::lines` with `BuRead::read_line` to reduce memory allocations.
-rw-r--r--src/tools/compiletest/src/header.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 34f9ac037b4..2b6016087c6 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -628,12 +628,18 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut dyn FnMut(&str)) {
     // It took me like 2 days to debug why compile-flags weren’t taken into account for my test :)
     let comment_with_brace = comment.to_string() + "[";
 
-    let rdr = BufReader::new(File::open(testfile).unwrap());
-    for ln in rdr.lines() {
+    let mut rdr = BufReader::new(File::open(testfile).unwrap());
+    let mut ln = String::new();
+
+    loop {
+        ln.clear();
+        if rdr.read_line(&mut ln).unwrap() == 0 {
+            break;
+        }
+
         // Assume that any directives will be found before the first
         // module or function. This doesn't seem to be an optimization
         // with a warm page cache. Maybe with a cold one.
-        let ln = ln.unwrap();
         let ln = ln.trim();
         if ln.starts_with("fn") || ln.starts_with("mod") {
             return;