Skip to content

Commit

Permalink
Merge pull request #1327 from jf2048/gstring-deref
Browse files Browse the repository at this point in the history
codegen: Use GString::as_str instead of Option<GString>::as_deref
  • Loading branch information
sdroege authored Mar 13, 2022
2 parents a4ffdd5 + 9515572 commit bb52094
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/codegen/function_body_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ impl Builder {
add_chunk_for_type(env, par.typ, par, &mut body, &ty_name, nullable);
if is_gstring(&ty_name) {
if *nullable {
arguments.push(Chunk::Name(format!("{}.as_ref().as_deref()", par.name)));
arguments.push(Chunk::Name(format!(
"(*{}).as_ref().map(|s| s.as_str())",
par.name
)));
} else {
arguments.push(Chunk::Name(format!("{}.as_str()", par.name)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/trampoline_from_glib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ impl TrampolineFromGlib for Transformation {
);
} else if nullable && is_borrow {
if is_gstring(&type_name) {
right = format!("{}.as_ref().as_deref()", right);
right = format!("(*{}).as_ref().map(|s| s.as_str())", right);
} else {
right = format!("{}.as_ref().as_ref()", right);
}
} else if is_gstring(&type_name) {
right = format!("{}.as_deref()", right);
right = format!("{}.as_str()", right);
} else {
right = format!("{}.as_ref()", right);
}
Expand Down

0 comments on commit bb52094

Please sign in to comment.