Skip to content

Commit c286284

Browse files
committed
Implement suggested improvements
1 parent c64d510 commit c286284

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

compiler-core/src/build/package_compiler.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ where
328328
app_file_config: Option<&ErlangAppCodegenConfiguration>,
329329
) -> Result<(), Error> {
330330
let mut written = HashSet::new();
331-
let native_modules: Vec<EcoString>;
332331
let build_dir = self.out.join(paths::ARTEFACT_DIRECTORY_NAME);
333332
let include_dir = self.out.join("include");
334333
let io = self.io.clone();
@@ -353,13 +352,13 @@ where
353352
// version and not the newly compiled version.
354353
Erlang::new(&build_dir, &include_dir).render(io.clone(), modules)?;
355354

356-
if self.compile_beam_bytecode {
355+
let native_modules: Vec<EcoString> = if self.compile_beam_bytecode {
357356
written.extend(modules.iter().map(Module::compiled_erlang_path));
358-
native_modules = self.compile_erlang_to_beam(&written)?;
357+
self.compile_erlang_to_beam(&written)?
359358
} else {
360359
tracing::debug!("skipping_erlang_bytecode_compilation");
361-
native_modules = Vec::new();
362-
}
360+
Vec::new()
361+
};
363362

364363
if let Some(config) = app_file_config {
365364
ErlangApp::new(&self.out.join("ebin"), config).render(

compiler-core/src/codegen.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,18 @@ impl<'a> ErlangApp<'a> {
154154
}
155155

156156
fn format_atom(s: &EcoString) -> EcoString {
157-
match s.chars().next() {
158-
Some(first_char) => {
159-
// Check if first character is not lowercase
160-
let needs_quotes = !first_char.is_ascii_lowercase();
157+
let mut chars = s.chars();
161158

162-
// Check if string contains any characters other than alphanumeric, underscore, or @
163-
let contains_special = s
164-
.chars()
165-
.any(|c| !(c.is_alphanumeric() || c == '_' || c == '@'));
159+
let Some(first) = chars.next() else {
160+
return "''".into();
161+
};
166162

167-
if needs_quotes || contains_special {
168-
EcoString::from(format!("'{}'", s))
169-
} else {
170-
s.clone()
171-
}
172-
}
173-
None => EcoString::from("''"),
163+
let needs_escape = |c: char| !(c.is_alphanumeric() || c == '_' || c == '@');
164+
165+
if !first.is_ascii_lowercase() || chars.any(needs_escape) {
166+
format!("'{}'", s).into()
167+
} else {
168+
s.clone()
174169
}
175170
}
176171
}

0 commit comments

Comments
 (0)