diff options
Diffstat (limited to 'bindgen/codegen/mod.rs')
-rw-r--r-- | bindgen/codegen/mod.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e0d96cd1..c7ac59db 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2421,7 +2421,7 @@ trait MethodCodegen { &self, ctx: &BindgenContext, methods: &mut Vec<proc_macro2::TokenStream>, - method_names: &mut HashMap<String, usize>, + method_names: &mut HashSet<String>, result: &mut CodegenResult<'a>, parent: &CompInfo, ); @@ -2432,7 +2432,7 @@ impl MethodCodegen for Method { &self, ctx: &BindgenContext, methods: &mut Vec<proc_macro2::TokenStream>, - method_names: &mut HashMap<String, usize>, + method_names: &mut HashSet<String>, result: &mut CodegenResult<'a>, _parent: &CompInfo, ) { @@ -2499,16 +2499,22 @@ impl MethodCodegen for Method { return; } - let count = { - let count = method_names.entry(name.clone()).or_insert(0); - *count += 1; - *count - 1 - }; + if method_names.contains(&name) { + let mut count = 1; + let mut new_name; + + while { + new_name = format!("{}{}", name, count); + method_names.contains(&new_name) + } { + count += 1; + } - if count != 0 { - name.push_str(&count.to_string()); + name = new_name; } + method_names.insert(name.clone()); + let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { write!(&mut function_name, "{}", times_seen).unwrap(); |