Skip to content

Commit

Permalink
Merge pull request #191 from mcorino/develop
Browse files Browse the repository at this point in the history
prevent code bloat through unnecessary overloads
  • Loading branch information
mcorino committed Oct 5, 2023
2 parents 9c20e42 + 4f2f721 commit 1442a76
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions rakelib/lib/director.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,25 @@ def handle_item_rename(defmod, fullname, rb_name)
end
end

def handle_duplicate_const_overloads(cls)
cls.methods.each do |mtd|
unless mtd.is_ctor || mtd.is_dtor || mtd.is_operator || !mtd.has_overloads
# ignore any non-const overloads which match a const overload with the same signature
# and only differ in returning a non-const type vs a const type
# (as Ruby has no notion of const types these are essentially the same when wrapped)
non_const_ovls = mtd.all.select { |ovl| !ovl.ignored && !ovl.is_const }
unless non_const_ovls.empty?
mtd.all.select { |ovl| !ovl.ignored && ovl.is_const }.each do |const_ovl|
non_const_ovl = non_const_ovls.find { |nco| !nco.ignored && nco.argument_list.strip == const_ovl.argument_list.strip }
if non_const_ovl && non_const_ovl.type.strip == const_ovl.type.sub('const ', '').strip
non_const_ovl.ignore
end
end
end
end
end
end

def process(gendoc: false)
# extract the module definitions
defmod = Extractor.extract_module(spec.package, spec.module_name, spec.name, spec.items, gendoc: gendoc)
Expand Down Expand Up @@ -367,6 +386,12 @@ def process(gendoc: false)
spec.includes.merge(cls.includes) unless cls.includes.empty?
end
end
# prevent unnecessary code bloat
defmod.classes.each do |cls|
unless cls.ignored
handle_duplicate_const_overloads(cls)
end
end
# TODO - should we just ignore all deprecations?
# create deprecated function proxies unless deprecates suppressed
unless Config.instance.no_deprecate
Expand Down

0 comments on commit 1442a76

Please sign in to comment.