Skip to content

Commit

Permalink
FIXUP: Simplify the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Dec 6, 2020
1 parent 6d32c5c commit ddf8357
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/analysis/special_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,28 @@ pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType, obj: &GObje
let mut destroy = None;

for (pos, func) in functions.iter_mut().enumerate() {
if is_stringify(func) {
let type_ = Type::extract(&func.name).unwrap_or(Type::Stringify);
let type_ = Type::extract(&func.name);

let type_ = match type_ {
Some(Type::Display) if is_stringify(func) => type_,
Some(Type::Display) => None,
None if is_stringify(func) => Some(Type::Stringify),
t => t,
};

if let Some(type_) = type_ {
if func.name == "destroy" {
destroy = Some((func.glib_name.clone(), pos));
continue;
}
if !update_func(func, type_, parent_type, obj) {
continue;
}
if func.name == "copy" {
has_copy = true;
} else if func.name == "free" {
has_free = true;
}

let return_transfer_none = func.ret.parameter.as_ref().map_or(false, |ret| {
ret.transfer == crate::library::Transfer::None
Expand All @@ -132,7 +148,8 @@ pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType, obj: &GObje
});

// Assume only enumerations and bitfields can return static strings
let returns_static_ref = return_transfer_none
let returns_static_ref = matches!(type_, Type::Display | Type::Stringify)
&& return_transfer_none
&& matches!(parent_type, LibType::Enumeration(_) | LibType::Bitfield(_))
// We cannot mandate returned lifetime if this is not generated.
// (And this prevents an unused std::ffi::CStr from being emitted below)
Expand All @@ -146,28 +163,6 @@ pub fn extract(functions: &mut Vec<FuncInfo>, parent_type: &LibType, obj: &GObje
version: func.version,
},
);
} else if let Some(type_) = Type::extract(&func.name) {
if func.name == "destroy" {
destroy = Some((func.glib_name.clone(), pos));
continue;
}
if !update_func(func, type_, parent_type, obj) {
continue;
}
if func.name == "copy" {
has_copy = true;
} else if func.name == "free" {
has_free = true;
}

specials.insert(
type_,
Info {
glib_name: func.glib_name.clone(),
returns_static_ref: false,
version: func.version,
},
);
}
}

Expand Down

0 comments on commit ddf8357

Please sign in to comment.