Skip to content

Commit de597da

Browse files
authored
Merge pull request #3909 from element-hq/quenting/buf-read-translations
Buffer reading of translation files
2 parents 8948d24 + 1e08844 commit de597da

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/i18n-scan/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// which is annoying with this clippy lint
99
#![allow(clippy::default_constructed_unit_structs)]
1010

11-
use std::fs::File;
11+
use std::{fs::File, io::BufReader};
1212

1313
use ::minijinja::{machinery::WhitespaceConfig, syntax::SyntaxConfig};
1414
use camino::Utf8PathBuf;
@@ -50,8 +50,9 @@ fn main() {
5050

5151
// Open the existing translation file if one was provided
5252
let mut tree = if let Some(path) = &options.existing {
53-
let mut file = File::open(path).expect("Failed to open existing translation file");
54-
serde_json::from_reader(&mut file).expect("Failed to parse existing translation file")
53+
let file = File::open(path).expect("Failed to open existing translation file");
54+
let mut reader = BufReader::new(file);
55+
serde_json::from_reader(&mut reader).expect("Failed to parse existing translation file")
5556
} else {
5657
TranslationTree::default()
5758
};

crates/i18n/src/translator.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7-
use std::{collections::HashMap, fs::File, str::FromStr};
7+
use std::{collections::HashMap, fs::File, io::BufReader, str::FromStr};
88

99
use camino::{Utf8Path, Utf8PathBuf};
1010
use icu_list::{ListError, ListFormatter, ListLength};
@@ -135,12 +135,14 @@ impl Translator {
135135
Err(source) => return Err(LoadError::InvalidLocale { path, source }),
136136
};
137137

138-
let mut file = match File::open(&path) {
138+
let file = match File::open(&path) {
139139
Ok(file) => file,
140140
Err(source) => return Err(LoadError::ReadFile { path, source }),
141141
};
142142

143-
let content = match serde_json::from_reader(&mut file) {
143+
let mut reader = BufReader::new(file);
144+
145+
let content = match serde_json::from_reader(&mut reader) {
144146
Ok(content) => content,
145147
Err(source) => return Err(LoadError::Deserialize { path, source }),
146148
};

0 commit comments

Comments
 (0)