diff --git a/flamegraphs/06-use-read_line/flamegraph.svg b/flamegraphs/06-use-read_line/flamegraph.svg
new file mode 100644
index 0000000..776d59a
--- /dev/null
+++ b/flamegraphs/06-use-read_line/flamegraph.svg
@@ -0,0 +1,491 @@
+
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index c04149d..d9920f7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,7 @@ struct StationValues {
count: u32,
}
-fn read_line(data: String) -> (String, f32) {
+fn read_line(data: &str) -> (String, f32) {
let mut parts = data.split(';');
let station_name = parts.next().expect("Failed to parse station name");
let value_str = parts.next().expect("Failed to parse value string");
@@ -35,10 +35,15 @@ fn read_line(data: String) -> (String, f32) {
}
// Calculate the station values
-fn calculate_station_values(data: BufReader) -> FxHashMap {
+fn calculate_station_values(reader: &mut BufReader) -> FxHashMap {
let mut result: FxHashMap = FxHashMap::default();
- for line in data.lines() {
- let line = line.expect("Failed to read line");
+ let mut buf = String::new();
+
+ while let Ok(bytes_read) = reader.read_line(&mut buf) {
+ if bytes_read == 0 {
+ break;
+ }
+ let line = buf.trim();
let (station_name, value) = read_line(line);
result
.entry(station_name)
@@ -58,6 +63,9 @@ fn calculate_station_values(data: BufReader) -> FxHashMap