@@ -18,16 +18,15 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
1818 "// This file contains embedded English locale files"
1919 ) ?;
2020 writeln ! ( embedded_file) ?;
21- writeln ! ( embedded_file , "use std::collections::HashMap;" ) ? ;
21+ // No imports needed for match-based lookup
2222 writeln ! ( embedded_file) ?;
2323
24- // Start the function that returns embedded locales
24+ // Generate optimized lookup function instead of HashMap
2525 writeln ! (
2626 embedded_file,
27- "pub fn get_embedded_locales( ) -> HashMap<&'static str, &'static str> {{"
27+ "pub fn get_embedded_locale(key: &str ) -> Option< &'static str> {{"
2828 ) ?;
29- writeln ! ( embedded_file, " let mut locales = HashMap::new();" ) ?;
30- writeln ! ( embedded_file) ?;
29+ writeln ! ( embedded_file, " match key {{" ) ?;
3130
3231 // Try to detect if we're building for a specific utility by checking build configuration
3332 // This attempts to identify individual utility builds vs multicall binary builds
@@ -44,8 +43,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
4443 }
4544 }
4645
47- writeln ! ( embedded_file) ?;
48- writeln ! ( embedded_file, " locales " ) ?;
46+ writeln ! ( embedded_file, " _ => None," ) ?;
47+ writeln ! ( embedded_file, " }} " ) ?;
4948 writeln ! ( embedded_file, "}}" ) ?;
5049
5150 embedded_file. flush ( ) ?;
@@ -127,12 +126,11 @@ fn embed_single_utility_locale(
127126
128127 if locale_path. exists ( ) {
129128 let content = fs:: read_to_string ( & locale_path) ?;
130- writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
129+ writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
131130 writeln ! (
132131 embedded_file,
133- " locales.insert( \" {util_name}/en-US.ftl\" , r###\" {content}\" ###); "
132+ " \" {util_name}/en-US.ftl\" => Some( r###\" {content}\" ###), "
134133 ) ?;
135- writeln ! ( embedded_file) ?;
136134
137135 // Tell Cargo to rerun if this file changes
138136 println ! ( "cargo:rerun-if-changed={}" , locale_path. display( ) ) ;
@@ -142,10 +140,10 @@ fn embed_single_utility_locale(
142140 let uucore_locale_path = project_root. join ( "src/uucore/locales/en-US.ftl" ) ;
143141 if uucore_locale_path. exists ( ) {
144142 let content = fs:: read_to_string ( & uucore_locale_path) ?;
145- writeln ! ( embedded_file, " // Common uucore locale" ) ?;
143+ writeln ! ( embedded_file, " // Common uucore locale" ) ?;
146144 writeln ! (
147145 embedded_file,
148- " locales.insert( \" uucore/en-US.ftl\" , r###\" {content}\" ###); "
146+ " \" uucore/en-US.ftl\" => Some( r###\" {content}\" ###), "
149147 ) ?;
150148 println ! ( "cargo:rerun-if-changed={}" , uucore_locale_path. display( ) ) ;
151149 }
@@ -185,12 +183,11 @@ fn embed_all_utility_locales(
185183 let locale_path = src_uu_dir. join ( util_name) . join ( "locales/en-US.ftl" ) ;
186184 if locale_path. exists ( ) {
187185 let content = fs:: read_to_string ( & locale_path) ?;
188- writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
186+ writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
189187 writeln ! (
190188 embedded_file,
191- " locales.insert( \" {util_name}/en-US.ftl\" , r###\" {content}\" ###); "
189+ " \" {util_name}/en-US.ftl\" => Some( r###\" {content}\" ###), "
192190 ) ?;
193- writeln ! ( embedded_file) ?;
194191
195192 // Tell Cargo to rerun if this file changes
196193 println ! ( "cargo:rerun-if-changed={}" , locale_path. display( ) ) ;
@@ -201,10 +198,10 @@ fn embed_all_utility_locales(
201198 let uucore_locale_path = project_root. join ( "src/uucore/locales/en-US.ftl" ) ;
202199 if uucore_locale_path. exists ( ) {
203200 let content = fs:: read_to_string ( & uucore_locale_path) ?;
204- writeln ! ( embedded_file, " // Common uucore locale" ) ?;
201+ writeln ! ( embedded_file, " // Common uucore locale" ) ?;
205202 writeln ! (
206203 embedded_file,
207- " locales.insert( \" uucore/en-US.ftl\" , r###\" {content}\" ###); "
204+ " \" uucore/en-US.ftl\" => Some( r###\" {content}\" ###), "
208205 ) ?;
209206 println ! ( "cargo:rerun-if-changed={}" , uucore_locale_path. display( ) ) ;
210207 }
@@ -220,7 +217,7 @@ fn embed_static_utility_locales(
220217
221218 writeln ! (
222219 embedded_file,
223- " // Static utility locales for crates.io builds"
220+ " // Static utility locales for crates.io builds"
224221 ) ?;
225222
226223 let manifest_dir = env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap_or_default ( ) ;
@@ -232,12 +229,11 @@ fn embed_static_utility_locales(
232229 let uucore_locale_file = Path :: new ( & manifest_dir) . join ( "locales/en-US.ftl" ) ;
233230 if uucore_locale_file. is_file ( ) {
234231 let content = std:: fs:: read_to_string ( & uucore_locale_file) ?;
235- writeln ! ( embedded_file, " // Common uucore locale" ) ?;
232+ writeln ! ( embedded_file, " // Common uucore locale" ) ?;
236233 writeln ! (
237234 embedded_file,
238- " locales.insert( \" uucore/en-US.ftl\" , r###\" {content}\" ###); "
235+ " \" uucore/en-US.ftl\" => Some( r###\" {content}\" ###), "
239236 ) ?;
240- writeln ! ( embedded_file) ?;
241237 }
242238
243239 // Collect and sort for deterministic builds
@@ -255,12 +251,11 @@ fn embed_static_utility_locales(
255251 let locale_file = entry. path ( ) . join ( "locales/en-US.ftl" ) ;
256252 if locale_file. is_file ( ) {
257253 let content = std:: fs:: read_to_string ( & locale_file) ?;
258- writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
254+ writeln ! ( embedded_file, " // Locale for {util_name}" ) ?;
259255 writeln ! (
260256 embedded_file,
261- " locales.insert( \" {util_name}/en-US.ftl\" , r###\" {content}\" ###); "
257+ " \" {util_name}/en-US.ftl\" => Some( r###\" {content}\" ###), "
262258 ) ?;
263- writeln ! ( embedded_file) ?;
264259 }
265260 }
266261 }
0 commit comments