From fe0eebe60d354d7439b478ed9338a612644549c5 Mon Sep 17 00:00:00 2001
From: Tim Schubert <dadada@dadada.li>
Date: Sat, 28 Dec 2024 00:06:10 +0100
Subject: [PATCH] performance

---
 src/main.rs | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 78f1ca4..f956fd7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,41 +1,44 @@
 #![no_main]
 #![no_std]
 
-use core::iter::repeat;
+use core::{fmt::Write, iter::repeat};
 
-use heapless::Vec;
+use heapless::{String, Vec};
 use log::info;
 use system::with_stdout;
-use uefi::{prelude::*, print, println};
+use uefi::prelude::*;
 
 #[entry]
 fn main() -> Status {
     uefi::helpers::init().unwrap();
     info!("Hello world!");
 
-    const W: usize = 32;
-    const H: usize = 32;
+    const W: usize = 30;
+    const H: usize = 30;
 
     let mut life: Vec<Vec<bool, W>, H> = life();
     for (i, j) in [(15, 16), (16, 15), (16, 16), (17, 16), (17, 17)] {
         life[i][j] = true;
     }
 
-    for i in 0..100_000 {
-        with_stdout(|stdout| stdout.clear()).unwrap();
-        println!("Generation: {}", i);
+    for _i in 0..100_000 {
         life = gol(life.clone());
+        let mut out: String<{ (W * H) + H }> = String::default();
         for l in life.iter() {
             for cell in l.iter() {
                 if *cell {
-                    print!("X")
+                    out.push('X').unwrap()
                 } else {
-                    print!(" ")
+                    out.push(' ').unwrap()
                 }
             }
-            println!("");
+            out.push('\n').unwrap()
         }
-        boot::stall(1_000);
+        with_stdout(|stdout| {
+            stdout.reset(true).unwrap();
+            stdout.write_str(&out).unwrap()
+        });
+        boot::stall(100_000);
     }
 
     boot::stall(100_000_000);