Skip to content

Commit 0927768

Browse files
authored
Replace HashMap with BTreeMap to remove non-determinism in build (#104)
1 parent 042f3cd commit 0927768

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

crates/macro/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rust_i18n_support::{
33
is_debug, load_locales, I18nConfig, DEFAULT_MINIFY_KEY, DEFAULT_MINIFY_KEY_LEN,
44
DEFAULT_MINIFY_KEY_PREFIX, DEFAULT_MINIFY_KEY_THRESH,
55
};
6-
use std::collections::HashMap;
6+
use std::collections::BTreeMap;
77
use syn::{parse_macro_input, Expr, Ident, LitBool, LitStr, Token};
88

99
mod minify_key;
@@ -268,7 +268,7 @@ pub fn i18n(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
268268
}
269269

270270
fn generate_code(
271-
translations: HashMap<String, HashMap<String, String>>,
271+
translations: BTreeMap<String, BTreeMap<String, String>>,
272272
args: Args,
273273
) -> proc_macro2::TokenStream {
274274
let mut all_translations = Vec::<proc_macro2::TokenStream>::new();

crates/support/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use normpath::PathExt;
22
use std::fs::File;
33
use std::io::prelude::*;
4-
use std::{collections::HashMap, path::Path};
4+
use std::{collections::BTreeMap, path::Path};
55

66
mod atomic_str;
77
mod backend;
@@ -19,7 +19,7 @@ pub use minify_key::{
1919

2020
type Locale = String;
2121
type Value = serde_json::Value;
22-
type Translations = HashMap<Locale, Value>;
22+
type Translations = BTreeMap<Locale, Value>;
2323

2424
pub fn is_debug() -> bool {
2525
std::env::var("RUST_I18N_DEBUG").unwrap_or_else(|_| "0".to_string()) == "1"
@@ -43,9 +43,9 @@ fn merge_value(a: &mut Value, b: &Value) {
4343
pub fn load_locales<F: Fn(&str) -> bool>(
4444
locales_path: &str,
4545
ignore_if: F,
46-
) -> HashMap<String, HashMap<String, String>> {
47-
let mut result: HashMap<String, HashMap<String, String>> = HashMap::new();
48-
let mut translations = HashMap::new();
46+
) -> BTreeMap<String, BTreeMap<String, String>> {
47+
let mut result: BTreeMap<String, BTreeMap<String, String>> = BTreeMap::new();
48+
let mut translations = BTreeMap::new();
4949
let locales_path = match Path::new(locales_path).normalize() {
5050
Ok(p) => p,
5151
Err(e) => {
@@ -200,7 +200,7 @@ fn parse_file_v2(key_prefix: &str, data: &serde_json::Value) -> Option<Translati
200200
// zh-CN: 欢迎
201201
if text.is_string() {
202202
let key = format_keys(&[key_prefix, key]);
203-
let sub_trs = HashMap::from([(key, text.clone())]);
203+
let sub_trs = BTreeMap::from([(key, text.clone())]);
204204
let sub_value = serde_json::to_value(&sub_trs).unwrap();
205205

206206
trs.entry(locale.clone())
@@ -253,8 +253,8 @@ fn format_keys(keys: &[&str]) -> String {
253253
.join(".")
254254
}
255255

256-
fn flatten_keys(prefix: &str, trs: &Value) -> HashMap<String, String> {
257-
let mut v = HashMap::<String, String>::new();
256+
fn flatten_keys(prefix: &str, trs: &Value) -> BTreeMap<String, String> {
257+
let mut v = BTreeMap::<String, String>::new();
258258
let prefix = prefix.to_string();
259259

260260
match &trs {

0 commit comments

Comments
 (0)