Skip to content

Commit 6796a61

Browse files
committed
Implement suggested improvements
1 parent 1ed0576 commit 6796a61

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
@@ -324,7 +324,6 @@ where
324324
app_file_config: Option<&ErlangAppCodegenConfiguration>,
325325
) -> Result<(), Error> {
326326
let mut written = HashSet::new();
327-
let native_modules: Vec<EcoString>;
328327
let build_dir = self.out.join(paths::ARTEFACT_DIRECTORY_NAME);
329328
let include_dir = self.out.join("include");
330329
let io = self.io.clone();
@@ -349,13 +348,13 @@ where
349348
// version and not the newly compiled version.
350349
Erlang::new(&build_dir, &include_dir).render(io.clone(), modules)?;
351350

352-
if self.compile_beam_bytecode {
351+
let native_modules: Vec<EcoString> = if self.compile_beam_bytecode {
353352
written.extend(modules.iter().map(Module::compiled_erlang_path));
354-
native_modules = self.compile_erlang_to_beam(&written)?;
353+
self.compile_erlang_to_beam(&written)?
355354
} else {
356355
tracing::debug!("skipping_erlang_bytecode_compilation");
357-
native_modules = Vec::new();
358-
}
356+
Vec::new()
357+
};
359358

360359
if let Some(config) = app_file_config {
361360
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)