Skip to content

Commit

Permalink
Small code refactor (#6263)
Browse files Browse the repository at this point in the history
## Description
- Optimize code

## Checklist

- [ ] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [ ] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: IGI-111 <igi-111@protonmail.com>
Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
  • Loading branch information
3 people authored and esdrubal committed Aug 13, 2024
1 parent bb413fb commit dbae03a
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions sway-core/src/abi_generation/abi_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ impl TypeId {
resolved_type_id: TypeId,
) -> String {
let type_engine = engines.te();
let self_abi_str = type_engine.get(*self).abi_str(ctx, engines);
if self.is_generic_parameter(engines, resolved_type_id) {
format!("generic {}", type_engine.get(*self).abi_str(ctx, engines))
format!("generic {}", self_abi_str)
} else {
match (
&*type_engine.get(*self),
&*type_engine.get(resolved_type_id),
) {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Custom { .. }, TypeInfo::Enum { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => {
(TypeInfo::Custom { .. }, TypeInfo::Struct { .. })
| (TypeInfo::Custom { .. }, TypeInfo::Enum { .. })
| (TypeInfo::Custom { .. }, TypeInfo::Alias { .. }) => {
type_engine.get(resolved_type_id).abi_str(ctx, engines)
}
(TypeInfo::Tuple(fields), TypeInfo::Tuple(resolved_fields)) => {
Expand All @@ -57,7 +54,7 @@ impl TypeId {
format!("[{}; {}]", inner_type, count.val())
}
(TypeInfo::Custom { .. }, _) => {
format!("generic {}", type_engine.get(*self).abi_str(ctx, engines))
format!("generic {}", self_abi_str)
}
_ => type_engine.get(resolved_type_id).abi_str(ctx, engines),
}
Expand Down Expand Up @@ -185,19 +182,13 @@ fn call_path_display(ctx: &AbiStrContext, call_path: &CallPath) -> String {
return call_path.suffix.as_str().to_string();
}
let mut buf = String::new();
let root_name = ctx.program_name.as_deref();
for (index, prefix) in call_path.prefixes.iter().enumerate() {
let mut skip_prefix = false;
if index == 0 {
if let Some(root_name) = &ctx.program_name {
if prefix.as_str() == root_name.as_str() {
skip_prefix = true;
}
}
}
if !skip_prefix {
buf.push_str(prefix.as_str());
buf.push_str("::");
if index == 0 && Some(prefix.as_str()) == root_name {
continue;
}
buf.push_str(prefix.as_str());
buf.push_str("::");
}
buf.push_str(&call_path.suffix.to_string());

Expand Down

0 comments on commit dbae03a

Please sign in to comment.